iOS 文字属性
2015-08-17 16:06
393 查看
- (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs
-(void)drawRect:(CGRect)rect { self.backgroundColor=[UIColor whiteColor]; NSString *attrString =@hello word; NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30] }; //在词典中加入文本的字体 大小 [attrString drawInRect:CGRectMake(20,120,320,200)withAttributes:attrs]; } 置字体颜色
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor]//文字颜色 }; 二,NSParagraphStyleAttributeName 段落格式
-(void)drawRect:(CGRect)rect { NSString *attrString =@hello word; NSMutableParagraphStyle *paragraph=[[NSMutableParagraphStyle alloc]init]; paragraph.alignment=NSTextAlignmentCenter;//居中 NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor],//文字颜色 NSParagraphStyleAttributeName:paragraph,//段落格式 }; [attrString drawInRect:CGRectMake(20,120,320,200)withAttributes:attrs]; } 三,NSBackgroundColorAttributeName 背景颜色
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor],//文字颜色 NSParagraphStyleAttributeName:paragraph,//段落格式 NSBackgroundColorAttributeName:[UIColor blueColor],//背景色 }; 四,NSStrokeColorAttributeName 设置描边颜色,需要和NSStrokeWidthAttributeName 一起使用
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor],//文字颜色 NSParagraphStyleAttributeName:paragraph,//段落格式 //NSBackgroundColorAttributeName:[UIColor blueColor],//背景色 NSStrokeWidthAttributeName:@3, //描边宽度 NSStrokeColorAttributeName:[UIColor greenColor],//设置 描边颜色,和NSStrokeWidthAttributeName配合使用,设置了这个NSForegroundColorAttributeName就失效了 }; 五,NSStrikethroughStyleAttributeName 删除线
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor],//文字颜色 NSParagraphStyleAttributeName:paragraph,//段落格式 // NSBackgroundColorAttributeName:[UIColor blueColor],//背景色 NSStrokeWidthAttributeName:@3, //描边宽度 NSStrokeColorAttributeName:[UIColor greenColor],//设置 描边颜色,和NSStrokeWidthAttributeName配合使用,设置了这个NSForegroundColorAttributeName就失效了 NSStrikethroughStyleAttributeName:@1,//删除线,数字代表线条宽度 }; 六,NSUnderlineStyleAttributeName 下划线
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor],//文字颜色 NSParagraphStyleAttributeName:paragraph,//段落格式 // NSBackgroundColorAttributeName:[UIColor blueColor],//背景色 NSStrokeWidthAttributeName:@3, //描边宽度 NSStrokeColorAttributeName:[UIColor greenColor],//设置 描边颜色,和NSStrokeWidthAttributeName配合使用,设置了这个NSForegroundColorAttributeName就失效了 // NSStrikethroughStyleAttributeName:@1,//删除线,数字代表线条宽度 NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),//下划线,值为一个枚举类型,大家可以分别试试 }; 七,NSShadowAttributeName 设置阴影,他的对象是一个NSShadow的对象
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor],//文字颜色 NSParagraphStyleAttributeName:paragraph,//段落格式 // NSBackgroundColorAttributeName:[UIColor blueColor],//背景色 NSStrokeWidthAttributeName:@3, //描边宽度 NSStrokeColorAttributeName:[UIColor greenColor],//设置 描边颜色,和NSStrokeWidthAttributeName配合使用,设置了这个NSForegroundColorAttributeName就失效了 // NSStrikethroughStyleAttributeName:@1,//删除线,数字代表线条宽度 NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),//下划线,值为一个枚举类型,大家可以分别试试 NSShadowAttributeName:shadow,//设置阴影,复制为一个NSShadow 的对象 }; NSShadow
NSShadow *shadow=[[NSShadow alloc]init]; shadow.shadowBlurRadius=5;//阴影的模糊程度 shadow.shadowColor=[UIColor blueColor];//阴影颜色 shadow.shadowOffset=CGSizeMake(6, 6);//阴影相对原来的偏移
八,NSObliquenessAttributeName 倾斜
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的颜色 字体 大小 NSForegroundColorAttributeName:[UIColor redColor],//文字颜色 NSParagraphStyleAttributeName:paragraph,//段落格式 // NSBackgroundColorAttributeName:[UIColor blueColor],//背景色 NSStrokeWidthAttributeName:@3, //描边宽度 NSStrokeColorAttributeName:[UIColor greenColor],//设置 描边颜色,和NSStrokeWidthAttributeName配合使用,设置了这个NSForegroundColorAttributeName就失效了 // NSStrikethroughStyleAttributeName:@1,//删除线,数字代表线条宽度 NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),//下划线,值为一个枚举类型,大家可以分别试试 NSShadowAttributeName:shadow,//设置阴影,复制为一个NSShadow 的对象 NSObliquenessAttributeName:@1//倾斜程度 };
相关文章推荐
- iOS——常用开发工具
- iOS xcode 工程 项目 代码行数统计
- iOS开发 iOS8 分割线右移15像素 将其归零
- iOS SDK详解之IBInspectable和IB_DESIGNABLE-Storyboad动态刷新
- ios 基础数据类型
- 使用vmstat,iostat查看系统性能
- 【精】iOS GCD 详解
- ios弹出软键盘时fixed失效及点击空白处隐藏层的解决办法
- 30多个iOS常用动画,带详细注释
- [iOS]调用系统相机,相册,闪光灯
- iOS自动检查更新
- iOS开发系列--地图与定位
- iOS颜色16进制值转换RGB
- IOS开发笔记-01按钮操作-03.加法计算器界面搭建
- iOS 开发的9个超有用小技巧
- ios开发之视频播放
- iOS 开发的一些小技巧篇
- Generalized Matrioshkas
- ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结
- ios下mach_absolute_time获取精准时间