UIColor 获取 RGB 值

一、 UIColor 获取 RGB 值

UIColor *color = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];
const CGFloat *components = CGColorGetComponents(color.CGColor);
NSLog(@"Red: %f", components[0]);
NSLog(@"Green: %f", components[1]);
NSLog(@"Blue: %f", components[2]);
NSLog(@"Alpha: %f", components[3]);

二、 修改textField的placeholder的字体颜色、大小

self.textField.placeholder = @"username is in here!";
[self.textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[self.textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

推荐 使用attributedString进行设置.

NSString *string = @"";

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
    
    [attributedString addAttribute:NSForegroundColorAttributeName
                             value:[UIColor redColor]
                             range:NSMakeRange(0, [string length])];
    
    [attributedString addAttribute:NSFontAttributeName
                             value:[UIFont systemFontOfSize:16]
                             range:NSMakeRange(0, [string length])];
    
    self.textField.attributedPlaceholder = attributedString;

三、判断NSString为纯数字
//判断是否为整形:

- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

//判断是否为浮点形:

- (BOOL)isPureFloat:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
}

if( ![self isPureInt:insertValue.text] || ![self isPureFloat:insertValue.text])
{
    resultLabel.textColor = [UIColor redColor];
    
    resultLabel.text = @"警告:含非法字符,请输入纯数字!";
    
    return;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、简介 <<UITextField(文本框) : UITextField被用作项目中获取用户信息的重要控件.在A...
    无邪8阅读 10,877评论 0 1
  • IOS常用代码总结 1、设置UILabel行间距 NSMutableAttributedString* attrS...
    难却却阅读 3,638评论 0 0
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 5,252评论 0 3
  • 1. 打印View所有子视图 po [[self view]recursiveDescription] 2. la...
    浩成哥哥阅读 4,183评论 0 0
  • 2016年3月10日我们在一起了,也许是命中注定,机缘巧合的我们居然走在了一起,万万没有想过。很开心很幸福前所未有...
    洁妹儿阅读 1,592评论 0 0