IOS中UITextField和UILabel简单使用
2017-10-08 21:11
465 查看
自定义控件: 如何使在xib中awakeFromNib 中设置,
如果在类中,在initWithFrame 中设置
1. UITextField: 可以通过 TintColor属性设置光标颜色
self.tintColor = [UIColor whiteColor];
------------------------
通过NSAttributedString 设置占位符属性:
// 点击ctrl+NSForegroundColorAttributeName 里面去找
//
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
//
attributes[NSForegroundColorAttributeName] = [UIColor yellowColor];
//
attributes[NSBackgroundColorAttributeName] = [UIColor redColor];
//
attributes[NSUnderlineStyleAttributeName] = @YES;
//
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:attributes];
------------------------
通过NSAttributedString 设置字符串拼接方式:
// attributedText,通过字符串拼接
// attributedText,通过字符串拼接
// NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:self.placeholder];
// // 设置属性
// NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
// attributes[NSForegroundColorAttributeName] = [UIColor yellowColor];
// [string setAttributes:attributes range:NSMakeRange(0, 1)];
//
// NSMutableDictionary *attributes2 = [NSMutableDictionary dictionary];
// attributes2[NSBackgroundColorAttributeName] = [UIColor redColor];
// attributes2[NSUnderlineStyleAttributeName] = @YES;
// [string setAttributes:attributes2 range:NSMakeRange(0, 2)]; // set后面覆盖前面的,add 累加
// [string addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, 1)]; //从0开始的第1个字符设置颜色
// [string addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 1)];
// [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:NSMakeRange(1, 1)];
// self.attributedPlaceholder = string;
----------------- UILabel设置图文并排
// // 图文混排
// NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] init];
// // 1 - 你好
// NSAttributedString *first = [[NSAttributedString alloc] initWithString:@"你好"];
// [attributedText appendAttributedString:first];
//
// // 2 - 图片
// // 带有图片的附件对象
// NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
// attachment.image = [UIImage imageNamed:@"header_cry_icon"];
// CGFloat lineH = label.font.lineHeight;
// 设置图片和文字高度一致
// attachment.bounds = CGRectMake(0, - ((label.xmg_height - lineH) * 0.5 - 1), lineH, lineH);
// // 将附件对象包装成一个属性文字
// NSAttributedString *second = [NSAttributedString attributedStringWithAttachment:attachment];
// [attributedText appendAttributedString:second];
//
// // 3 - 哈哈哈
// NSAttributedString *third = [[NSAttributedString alloc] initWithString:@"哈哈哈"];
// [attributedText appendAttributedString:third];
//
// label.attributedText = attributedText;
// UILabel *label = [[UILabel alloc] init];
//// label.text = @"你好哈哈哈";
// NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"你好哈哈哈"];
// [text addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, 3)];
// [text addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 3)];
// label.attributedText = text;
// label.frame = CGRectMake(100, 100, 100, 25);
// [self.view addSubview:label];
-------- 导航控制器Label设置换行
// 设置Label文字换行
// UILabel *label = [[UILabel alloc] init];
// // 设置属性文字
// NSString *text = @"你好\n哈哈哈";
// NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text];
// [attributedText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:10] range:NSMakeRange(0, text.length)];
// [attributedText addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13] range:NSMakeRange(3, 3)];
// label.attributedText = attributedText;
// // 其他设置
// label.numberOfLines = 0;
// label.textAlignment = NSTextAlignmentCenter;
// label.frame = CGRectMake(0, 0, 100, 40);
// [self.view addSubview:label];
// self.navigationItem.titleView = label;
相关文章推荐
- iOS--UITextField的简单使用
- UILabel、UITextField、UIButton简单使用
- UILabel,UIButton,UITextField的简单使用
- iOS - UITextField简单使用
- 【iOS开发】简单UI部分UIButton的创建和UITextField的使用
- iOS-Cocos2d游戏开发】使用plist文件制作简单精灵
- iOS开发 block的简单使用
- IOS-datePicker的简单使用
- IOS下SQLite的简单使用
- iOS开发18:Storyboard的简单使用
- IOS-SegmentedControl(添加到Nav上)的简单使用方法
- ios简单使用core data
- IOS学习之UIPickerView控件的简单使用
- iOS学习之Table View的简单使用
- IOS UITextField使用
- IOS-NSNotification的简单使用流程:
- [iOS] NSInvocation简单使用
- iOS-简单使用core data
- IOS学习之UIPickerView控件的简单使用
- ios简单sqlite使用