OC 项目中遇到的一些知识总结

本文介绍如何自定义导航条标题样式、设置文本框左侧图标及占位符颜色,并提供判断输入法语言类型的代码。此外,还对比了fullResolutionImage与fullScreenImage在图片处理中的应用区别。

1. 自定义导航条的标题(文字大小和颜色)

直接上代码

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.font = [UIFont systemFontOfSize:17];
    titleLabel.textAlignment = NSTextAlignmentCenter;

    titleLabel.text=@"登录";
    self.navigationItem.titleView = titleLabel;

2. 设置textField的左边图片

直接上代码

    self.textFiled.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_login_shouji"]];
    self.textFiled.leftViewMode = UITextFieldViewModeAlways;

3. 设置textfield的placeholder颜色

直接上代码


self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.loginInputId.placeholder attributes:@{NSForegroundColorAttributeName: color}];

4. 判断输入法是否是中文

怒上代码 中文是zh-cn,应为是en-us,其他地区见
地区代码

 BOOL isChinese = [[[UIApplication sharedApplication] textInputMode].primaryLanguage isEqualToString:@"zh-cn"];

5. fullResolutionImage 与fullScreenImage

参考自使用ALAssetsLibrary读取所有照片
ALAssetRepresentation的 metadata 方法很慢,我在iPhone4 iOS5.1.1中测试,此方法返回需要40-50ms,所以获取图片的个各种属性尽量直接从ALAssetRepresentation中获取,不要读取metadata,调用多次也确实很容易会memory warning,

系统”相册”程序显示的图片是 fullScreenImage ,而不是 fullResolutionImage ,fullResolutionImage尺寸太大,在手机端显示推荐用fullScreenImage。
fullScreenImage已被调整过方向,可直接使用,即

[UIImage imageWithCGImage:representation.fullScreenImage];

使用fullResolutionImage要自己调整方法和scale,即

[UIImage imageWithCGImage:representation.fullResolutionImage scale:representation.scale orientation:representation.orientation];
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值