苹果开发 笔记(28)

今天看源代码的时候,遇到一个按钮文本颜色显示过浅问题。现象描述为这样子。按钮点击后将背景色设置为蓝色底,点击选中的时候文本亮度显示出现过浅现象。原因发现是按钮类型不一样,导致这一显示问题。

第一次设置了 UIButtonTypeRoundedRect 的类型,然后

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitleColor:RGB(0x778087, 1.0) forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];

这里写图片描述
第二次改回默认的类型UIButtonTypeCustom

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont  systemFontOfSize:16];
[button setTitleColor:RGB(0x778087, 1.0) forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];

这里写图片描述

两者显示颜色却不一样了。设置UIButtonTypeCustom 选中状态的高亮会明显一点。

字符串高度计算
这几天一直在看这方面的资料

- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context NS_AVAILABLE_IOS(7_0);

这个方法是字符串NSString分类其中一个方法,用于字符串来获取字符串的高度和宽度。局限在7.0以上的版本,要是6.0的系统使用就会出问题。

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode NS_DEPRECATED_IOS(2_0, 7_0, "Use -boundingRectWithSize:options:attributes:context:"); // NSTextAlignment is not needed to determine size

在7.0 以下的版本 这个方法可用于计算高度,在7.0后就删除了,为兼容两个版本这些方法对其进行版本设置UIDevice 可以获取当前的版本情况的信息。

  CGFloat version = [[UIDevice currentDevice] systemVersion].floatValue;// < 7
    if (version <7)
    {
     //计算值  
   }
    else
    { 

   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值