ios-drawInRect:withAttributes

http://stackoverflow.com/questions/19274408/drawinrectwithattributes-vs-drawinrectwithfontlinebreakmodealignment
- (void)drawRect:(CGRect)frame
{
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.lineBreakMode = NSLineBreakByWordWrapping;
textStyle.alignment = NSTextAlignmentCenter;
UIFont *textFont = [UIFont systemFontOfSize:16];

NSString *text = @"Lorem ipsum";

// iOS 7 way
[text drawInRect:frame withAttributes:@{NSFontAttributeName:textFont, NSParagraphStyleAttributeName:textStyle}];

// pre iOS 7 way
CGFloat margin = 16;
CGRect bottomFrame = CGRectMake(0, margin, frame.size.width, frame.size.height - margin);
[text drawInRect:bottomFrame withFont:textFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentCenter];
}

时间: 2024-08-29 14:05:42

ios-drawInRect:withAttributes的相关文章

drawInRect:withAttributes:

- (void)drawRect:(CGRect)frame { NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; textStyle.lineBreakMode = NSLineBreakByWordWrapping; textStyle.alignment = NSTextAlignmentCenter; UIFont *textFont =

iOS 根据文字字数动态确定Label宽高

iOS7中用以下方法 - (CGSize)sizeWithAttributes:(NSDictionary *)attrs; 替代过时的iOS6中的- (CGSize)sizeWithFont:(UIFont *)font 方法 // iOS7_API_根据文字 字数动态确定Label宽高 // 设置Label的字体 HelveticaNeue Courier UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:24.0f]

< IOS开发 >使用CGContextRef绘制文字时的设置

NSString *str = @"hello"; //字体 UIFont *font = [UIFont systemFontOfSize:16.0]; //文本风格,设置居中 NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [paragraphStyle setAlignment:NSTextAlignmentCenter]; //文本

iOS SDK更新换代的功能

wantsFullScreenLayout已经作废了,取而代之是 1.edgesForExtendedLayout 这个属性是UIExtendedEdge类型,用来制定视图的哪条边需要扩展.比如UIRectEdgeTop,它把视图区域顶部扩展到statusBar(以前是navigationBar下面):UIRectEdgeBottom是把区域底部扩展到屏幕下方边缘.默认值是UIRectEdgeAll. 2.extendedLayoutIncludesOpaqueBars 如果你使用了不透明的导航

iOS_根据文字字数动态确定Label宽高

iOS7中用以下方法 - (CGSize)sizeWithAttributes:(NSDictionary *)attrs; 替代过时的iOS6中的- (CGSize)sizeWithFont:(UIFont *)font 方法 // iOS7_API_根据文字 字数动态确定Label宽高 // 设置Label的字体 HelveticaNeue Courier UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:24.0f]

视图层和视图类 、 绘制

1 绘制基本图形 1.1 问题 IOS中进行绘制比较方便,只需要在视图类(UIView及其子类)中重写drawRect方法,将绘制代码要写在该方法中即可,此方法会在视图显示前自动调用.本案例重写视图类中的drawRect方法,绘制一个简单的图形,如图-1所示: 图-1 1.2 方案 首先在创建好的Xcode项目中创建一个TRMyView类,继承至UIView.在Storyboard中拖放一个View控件,在右边栏的检查器中将View和TRMyView类进行绑定,并将背景设置为紫色. 然后在TRM

媒体层:Core Graphics(绘图)

1.简介: 基于C的API,用于绘图, 当使用UIKit来创建按钮.图像或者其他UIView的子类时,UIKit会使用Core Graphics来将这些元素绘制在屏幕上 可创建直线.路径.渐变.文字.图像等内容 CGContextRef:图像上下文.画布 从UIView的子类中获取它的当前上下文UIGraphicsGetCurrentContext(),然后重写drawRect方法 绘图动作是顺序的,每个动作都是在前一个动作的基础上面完成的 只要iOS任务一个视图需要被刷新或者重绘drawRec

141设置屏幕中文本的横向对齐方式(扩展知识:设置标签行间距)

效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @end ViewController.m 1 #import "ViewController.h" 2 #import "KMLabel.h" 3 4 @interface ViewController () 5 - (void)layoutUI; 6 @

iOS7 SDK各种坑——手Q团队总结

http://s.p.qq.com/pub/show?p=82e0c8d9&id=4f6fdb7610fed&plg_auth=1&pt=4&puin=2195769561&idx=1&st=3 2014年04月14日 antonyzhao(赵峰) SNG即通产品部\平台开发组副组长 IViewController布局 wantsFullScreenLayout已经作废了,取而代之是 1.edgesForExtendedLayout 这个属性是UIExten

iOS 小技巧总结,绝对有你想要的

iOS 小技巧总结,绝对有你想要的 原文链接:http://www.jianshu.com/p/4523eafb4cd4 在这里总结一些 iOS 开发中的小技巧,能大大方便我们的开发,持续更新. —— 由 xcvxvxc分享 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 在viewWillAppear里面添加如下代码: //分组列表头部空白处理 CGRect frame = myTableView.tableHeade