1.判斷一個對象是否繼承某個類
用cell的子類來做范例
BOOL inherited = ![templateLayoutCell isMemberOfClass:UITableViewCell.class];
2.判斷某個方法是否覆寫
用cell的子類來做范例
SEL selector = @selector(sizeThatFits:);
BOOL overrided = [templateLayoutCell.class instanceMethodForSelector:selector] != [UITableViewCell instanceMethodForSelector:selector];
3.計算一個cell的ContentView的寬度
此處的self是指某個具體的cell
CGFloat contentViewWidth = CGRectGetWidth(self.frame);
// If a cell has accessory view or system accessory type, its content view's width is smaller
// than cell's by some fixed values.
if (templateLayoutCell.accessoryView) {
contentViewWidth -= 16 + CGRectGetWidth(templateLayoutCell.accessoryView.frame);
} else {
static const CGFloat systemAccessoryWidths[] = {
[UITableViewCellAccessoryNone] = 0,
[UITableViewCellAccessoryDisclosureIndicator] = 34,
[UITableViewCellAccessoryDetailDisclosureButton] = 68,
[UITableViewCellAccessoryCheckmark] = 40,
[UITableViewCellAccessoryDetailButton] = 48
};
contentViewWidth -= systemAccessoryWidths[templateLayoutCell.accessoryType];
}
4. autoresizesSubviews
如果視圖的autoresizesSubviews屬性被設(shè)置為 NO
贺拣,則該視圖的直接子視圖的所有自動尺寸調(diào)整行為將被忽略掰派。類似地达皿,如果一個子視圖的自動尺寸調(diào)整掩碼被設(shè)置為 UIViewAutoresizingNone,則該子視圖的尺寸將不會被調(diào)整侍咱,因而其直接子視圖的尺寸也不會被調(diào)整住诸。
- 請注意:為了使自動尺寸調(diào)整的行為正確长赞,視圖的transform屬性必須設(shè)置為恒等變換声怔;其它變換下的尺寸自動調(diào)整行為是未定義的。
自動尺寸調(diào)整行為可以適合一些布局的要求气笙,但是如果您希望更多地控制視圖的布局次企,可以在適當(dāng)?shù)囊晥D類中重載layoutSubviews方法。
5.判斷設(shè)備是否是橫屏
#define IS_LANDSCAPE ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeRight)