How can I create a UIColor from a hex string?

后端 未结 30 1678
北恋
北恋 2020-11-22 16:53

How can I create a UIColor from a hexadecimal string format, such as #00FF00?

30条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 17:36

    This is nice with cocoapod support

    https://github.com/mRs-/HexColors

    // with hash
    NSColor *colorWithHex = [NSColor colorWithHexString:@"#ff8942" alpha:1];
    
    // wihtout hash
    NSColor *secondColorWithHex = [NSColor colorWithHexString:@"ff8942" alpha:1];
    
    // short handling
    NSColor *shortColorWithHex = [NSColor colorWithHexString:@"fff" alpha:1]
    

提交回复
热议问题