苹果开发 笔记(28)

来源:互联网 发布:网络公安部举报诈骗 编辑:程序博客网 时间:2024/06/03 18:26

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

第一次设置了 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    {    }
0 0
原创粉丝点击