iOS开发小技巧

1.去掉UISearchbar的边框线,改变输入框背景色

- (void)setSearchBarBackgroundColor: (UIColor *)searchBarBackgroundColor{

_searchBarBackgroundColor =  searchBarBackgroundColor;

for ( UIView*subView in [[self.searchBar.subviews lastObject ]subviews] ) {

if ( [[subViewclass] is SubclassOfClass:[UITextField class]] ) {

UITextField *textField = (UITextField*)subView;

textField.backgroundColor =  searchBarBackgroundColor;

}

if ( [subView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] ) {

[subView removeFromSuperview];

}

}

}

2.给View添加单边框

- (void)addBorderWithColor: (UIColor*) color frame:(CGRect)frame;

- (void)addBorderWithColor:(UIColor*)color frame:(CGRect)frame {

CALayer *border = [CALayer layer];

border.backgroundColor = color.CGColor;

border.frame = frame;

[self.layer addSublayer:border];

}

3.数组去重(kvc)

self.xxxArray = [self.xxxArray valueForKeyPath:@"@distinctUnionOfObjects.self"];

4.导航栏透明

- (void)viewWillAppear:(BOOL)animated{

[superview WillAppear:animated];

[[self.navigationController.navigationBarsubviews]objectAtIndex:0].alpha = 0;

}

- (void)viewWillDisappear:(BOOL)animated{

[superview WillDisappear:animated];

[[self.navigationController.navigationBarsubviews]objectAtIndex:0].alpha = 1;

}


5.去掉某个View的子视图

[self.xxx.subviewsmakeObjectsPerformSelector:@selector(removeFromSuperview)];

6.UITableViewController修改tableView  Frame

-(void)viewDidLayoutSubviews {

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {

[self.tableView setSeparatorInset:UIEdgeInsetsZero];

}

if([self.tableView respondsToSelector:@selector(setLayoutMargins:)]){

[self.tableView setLayoutMargins:UIEdgeInsetsZero];

}

[self.tableView setFrame:CGRectMake(0.0,0.0, _width, _height)];

}

7.tableview 初始化无cell线条

self.tableView.tableFooterView= [UIView new];

你可能感兴趣的:(iOS开发小技巧)