標籤:
1.遇到UI控制項沒有顯示的問題,可以給這個控制項設定背景色
假設這個控制項是UIBUtton
如果背景色能顯示,那問題就出在image和title值為空白
如果背景色不能顯示,重寫控制項的description方法,把控制項的frame列印出來分析
2.以下是列印UIView的frame的分類
#import <UIKit/UIKit.h>@interface UIView (Log)@end
1 #import "UIView+Log.h" 2 3 @implementation UIView (Log) 4 5 + (NSString *)searchAllSubviews:(UIView *)superview 6 { 7 NSMutableString *xml = [NSMutableString string]; 8 9 NSString *class = NSStringFromClass(superview.class);10 // 部分控制項的類名帶底線_,XML裡含底線_會報錯11 class = [class stringByReplacingOccurrencesOfString:@"_" withString:@""]; 12 13 if ([class isEqualToString:@"UIScrollView"]) {14 UIScrollView *realView= (UIScrollView *)superview;15 [xml appendFormat:@"<%@ frame=\"%@\" contentSize=\"%@\" >\n", class, NSStringFromCGRect(superview.frame),NSStringFromCGSize(realView.contentSize)];16 }else{17 [xml appendFormat:@"<%@ frame=\"%@\">\n", class, NSStringFromCGRect(superview.frame)];18 }19 20 for (UIView *childView in superview.subviews) {21 NSString *subviewXml = [self searchAllSubviews:childView];22 [xml appendString:subviewXml];23 }24 [xml appendFormat:@"</%@>\n", class];25 return xml;26 27 }28 29 - (NSString *)description30 {31 return [UIView searchAllSubviews:self];32 }33 34 @end
3. 利用上面的分類,就可以很方便的列印UI控制項,把列印的資訊粘在XML檔案裡,用Firefox開啟,便於瀏覽
iOS UI控制項沒有顯示時的調試技巧