1、
-(void)performSelector
{
SEL selector = @selector(printImp);
IMP imp = [self methodForSelector:selector];
void (*setter)(id,SEL,BOOL) = (void(*)(id,SEL,BOOL))imp;
setter(self,selector,YES);
}
-(void)printImp
{
NSLog(@"MemoryCollectPerformance Print.....");
}
2、了解API以下的东西的话,依然可以利用Obj-C的runtime。 可以在这里看到 http://opensource.apple.com/source/objc4/objc4-493.11/runtime/ ,尤其是objc-runtime.m, 这里提供了很多学习用的"工具"。比如经典的method_exchangeImplementations(),您可以用它研究很多黑箱过程的来龙去脉。值得一提的是, 这种技巧(method swizzling)是合法的,可以在App Store 中使用! 苹果曾给使用了相关技巧的开发者发过邮件,表示出于安全性和稳定性最好不再使用, 但没有禁止。
3、界面布局
// 1、AutoLayout 手写
UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, 10, 10);
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints:@[
[NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:padding.top],
[NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:padding.left],
[NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:-padding.right],
[NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-padding.bottom]]];
// 2、VFL
NSDictionary* views = NSDictionaryOfVariableBindings(_tableView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_tableView]-30-|" options:NSLayoutFormatAlignAllTop | NSLayoutAttributeBottom metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_tableView]-30-|" options:NSLayoutFormatAlignAllLeft | NSLayoutAttributeRight metrics:nil views:views]];
// 3、Masonry
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view);
make.size.mas_equalTo(CGSizeMake(300, 200));
}];
//4、aotulayout(Xib)
来源:CSDN
作者:aimsgmiss
链接:https://blog.csdn.net/aimsgmiss/article/details/78895482