1. button 图标和文字位置设置
//文字
button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;```
//图标
[button setImage:[UIImage imageNamed:@"picture_name.png"] forState:UIControlStateNormal];
[button setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 65)];```
2. title的设置
self.tabBarItem.title = @"首页"; //只在没有嵌入navigation时生效
self.title = @"新闻"; //self.tabBarItem.title继承自self.title;
self.navigationItem.title = @"导航"; //如果不设置,和self.title的内容是一样的```
#####3. NavigationBar中间文字属性修改
self.navigationController.navigationBar.titleTextAttributes = @{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont boldSystemFontOfSize:16]
};
#####4. Label部分文字变色
NSString *str = @"this is a string";
NSMutableAttributedString *noteStr =
[[NSMutableAttributedString alloc] initWithString:str];
NSRange redRange = NSMakeRange(0, 20);
[noteStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:redRange];
[label setAttributedText:noteStr];
[label sizeToFit];
#####5. UISwitch修改大小
//不能设置frame,只能用缩放比例
switch.transform = CGAffineTransformMakeScale(0.75, 0.75);
#####6. 透明NavigationBar
//写法1
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
} - (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setShadowImage:nil];
[self.navigationController.navigationBar setBackgroundImage:nil
forBarMetrics:UIBarMetricsDefault];
}
//写法2 - (void)setNavBarImg:(UINavigationBar *)navBar
{
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
// if iOS 5.0 and later
[navBar setBackgroundImage:[UIImage imageNamed:@"background_detail_bg1"]
forBarMetrics:UIBarMetricsDefault];
}
else
{
UIImageView *imageView = (UIImageView *)[navBar viewWithTag:10];
[imageView setBackgroundColor:[UIColor clearColor]];
if (imageView == nil)
{
imageView =
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background_detail_bg1"]];
[imageView setTag:10];
[navBar insertSubview:imageView atIndex:0];
}
}
}
#####7. ScrollView顶部图片下拉变大效果
//以下代码作用是图片高度改变,宽度也会改变,因此只需要修改图片高度即可
ImageView.contentMode=UIViewContentModeScaleAspectFill;
网友评论