iOS UI控制項沒有顯示時的調試技巧

來源:互聯網
上載者:User

標籤:

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控制項沒有顯示時的調試技巧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.