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 *)description 30 { 31 return [UIView searchAllSubviews:self]; 32 } 33 34 @end
3. 利用上面的分类,就可以很方便的打印UI控件,把打印的信息粘在XML文件里,用火狐打开,便于浏览
时间: 2024-10-02 17:22:27