Objective-C文字加阴影方法总结
来源:互联网 发布:jquery json转数组 编辑:程序博客网 时间:2024/05/29 03:50
UILabel、UITextField可以直接设置shadow属性:
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(30, 30, 300, 50)]; label.text = @"UILabel文字阴影效果"; //阴影颜色 label.shadowColor = [UIColor redColor]; //阴影偏移 x,y为正表示向右下偏移 label.shadowOffset = CGSizeMake(1, 1); [self.view addSubview:label];
阴影可以设置的属性比较少,如果要进行更多的设置,就要在layer层进行设置,但要把背景色设置为透明。比如UITextView,就必须在layer进行设置,因为UITextView没有提供shadow相关的属性(吐槽一下连placeholder属性都没有。。。)
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(30, 80, 300, 50)]; textView.backgroundColor = [UIColor clearColor]; textView.font = [UIFont systemFontOfSize:17]; [self.view addSubview:textView]; textView.text = @"UITextView文字阴影效果"; //阴影透明度 textView.layer.shadowOpacity = 1.0; //阴影宽度 textView.layer.shadowRadius = 1.0; //阴影颜色 textView.layer.shadowColor = [UIColor redColor].CGColor; //映影偏移 textView.layer.shadowOffset = CGSizeMake(1, 1);
还有一种方案就是利用NSAttributedString属性字符串来设置阴影了,这种方法还可以控制range:
NSShadow *shadow = [[NSShadow alloc]init]; shadow.shadowBlurRadius = 1.0; shadow.shadowOffset = CGSizeMake(1, 1); shadow.shadowColor = [UIColor redColor]; [_attributedString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(1, _attributedString.length-1)];
0 0
- Objective-C文字加阴影方法总结
- Objective-C文字加阴影方法总结
- 文字加黑色阴影
- TextView加文字阴影
- 加阴影的方法
- 给图片加阴影加文字 和阴影背景图
- Objective-C常用方法总结
- CCLablTTF 给文字加阴影效果
- Objective-C 时间操作实用方法总结
- Objective C语言----类,对象,方法总结
- Objective-C收起键盘方法总结
- Objective-C页面跳转方法总结
- Objective-C延迟执行方法总结
- php使用Imagick给图片写文字加阴影效果
- Objective-C AES加解密
- 给文字加上阴影效果的方法
- 两种方法实现文字阴影效果
- 文字阴影
- idea和eclipse 的debug调试快捷键对比
- JavaScript将对象转换为JSON
- 表单填写后输回车跳转到下一个输入
- Blueprints - 蓝图之间的交互
- 自动调整linux系统时间和时区与Internet时间同步
- Objective-C文字加阴影方法总结
- 关于Android SQLite3多线程并发问题,学习笔记。
- 欢迎使用CSDN-markdown编辑器
- RedirectAttributes对象addFlashAttribute()的使用
- 字符串的组合
- 正则表达式简单汇总
- POJ2594
- 数据抓取常用:python时间转换
- Debug---Eclipse断点调试基础