【ios开发】添加颜色的不同方式

1、

-(UIButton *)yanzhengBtn {

    if (!_yanzhengBtn) {

        _yanzhengBtn = [[UIButton alloc] init];

        _yanzhengBtn.layer.backgroundColor = [UIColor whiteColor].CGColor;

        _yanzhengBtn.layer.borderColor = [UIColor colorWithRed:46/255.0 green:102/255.0 blue:240/255.0 alpha:1.0].CGColor;

        _yanzhengBtn.layer.cornerRadius = 10;

        _yanzhengBtn.layer.borderWidth = 1;

        _yanzhengBtn.titleLabel.font = [UIFont systemFontOfSize:13];

        [_yanzhengBtn setTitleColor:[UIColor colorWithRed:46/255.0 green:102/255.0 blue:240/255.0 alpha:1.0].CGColor forState:UIControlStateNormal];//[self colorFromHexRGB:@"2e66f0ff"]

        [_yanzhengBtn setTitle:@"验证" forState:UIControlStateNormal];

    }

    return _yanzhengBtn;

}

2、上面注释部分

//- (UIColor *)colorFromHexRGB:(NSString *)hexString {

//    unsigned rgbValue = 0;

//    NSScanner *scanner = [NSScanner scannerWithString:hexString];

//    [scanner setScanLocation:1]; // 跳过字符串开头的 #

//    [scanner scanHexInt:&rgbValue];

//    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0

//                           green:((rgbValue & 0xFF00) >> 8)/255.0

//                            blue:(rgbValue & 0xFF)/255.0

//                           alpha:1.0];

//}

你可能感兴趣的:(ios,cocoa,macos,objective-c)