1、Xcode调试技巧—在系统抛出异常处设置断点
有时候我们的程序不知道跑到哪个地方就 crash 了,而 crash 又很难重现。
保守的做法是在系统抛出异常之前设置断点,具体来说是在 objc_exception_throw处设置断点。
设置步骤为:首先在 XCode 按 CMD + 6,进入断点管理窗口;
然后点击右下方的 +,增加新的 Symbolic Breakpoint。
在 Symbol 一栏输入:objc_exception_throw,然后点击 done,完成。
这样在 Debug 模式下,如果程序即将抛出异常,就能在抛出异常处中断了。
比如在前面的代码中,我让 [firstObjctcrashTest]; 抛出异常。在 objc_exception_throw 处设置断点之后,程序就能在该代码处中断了,我们从而知道代码在什么地方出问题了。
2、计算UIlabel 随字体多行后的高度
+ (CGFloat)calcTextHeight:(int)textWidth text:(NSString *)text font:(int)fontSize {
CGRect bounds, result;
bounds = CGRectMake(0, 0, textWidth, 300);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont systemFontOfSize:fontSize];
label.text = text;
result = [label textRectForBounds:bounds limitedToNumberOfLines:20];
return result.size.height;
}
或者CGSize requiredSize = [introduceLabel.text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(296.0f, FLT_MAX) lineBreakMode:UILineBreakModeTailTruncation];
3、计算当前label随字体增加的长度(单行)
CGSize boundingSize = CGSizeMake(320.0f, CGFLOAT_MAX);
CGSize requiredSize = [status.user.username sizeWithFont:[UIFont boldSystemFontOfSize:13] constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
CGFloat requiredWidth = requiredSize.width;
4、view控件加边框
profileImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[profileImageButton.layer setMasksToBounds:YES];
[profileImageButton.layer setCornerRadius:4.0]; //设置矩形四个圆角半径
[profileImageButton.layer setBorderWidth:1.0]; //边框宽度
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){225.0/255.0, 225.0/255.0, 225.0/255.0, 1.0 });
iOS开发经验总结:
最新推荐文章于 2018-02-23 15:17:59 发布