iOS之界面修改方法

这篇博客介绍了如何在iOS应用中定制界面,包括设置自定义图片作为背景、改变导航栏字体和按钮颜色、定制导航栏背景、调整状态栏显示、用RGB颜色修改控件背景、使用自定义UITableViewCell、实现UITableView分割线顶头显示,以及将UIImageView变为圆形并添加阴影。教程详细说明了实现这些效果的具体步骤和代码片段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 修改界面背景为自定义图片

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Background_3.5.png"]]];

   

2. 修改导航栏字体颜色

NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[self.navigationController.navigationBar setTitleTextAttributes:attributes];


3. 修改导航栏按钮颜色

[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

4. 修改导航栏背景为自定义图片

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavigationBar.png"] forBarMetrics:UIBarMetricsDefault];

5. 修改状态栏字体颜色

先在info.plist中添加View controller-based status bar appearance字段,属性值设为NO

然后使用如下代码修改颜色

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];  // 白色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];  // 黑色


6. 使用RGB颜色修改控件背景

以UIButton为例

[settingsButton setBackgroundColor:[UIColor colorWithRed:194/255.0 green:19/255.0 blue:70/255.0 alpha:1]];

7. 使用自定义UITableViewCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *messageCellIdentifier = @"MessageCellIdentifier";
    
    static BOOL nibsRegistered=NO;
    if (!nibsRegistered)
    {
        UINib *nib=[UINib nibWithNibName:@"MessageTableViewCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:messageCellIdentifier];
        nibsRegistered=YES;
    }
    
    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellIdentifier];
    if (cell==nil)
    {
        cell=[[[NSBundle mainBundle]loadNibNamed:@"MessageTableViewCell" owner:nil options:nil]lastObject];
    }
    
    [cell setFontSize:settings.fontSize];
    NSInteger row = [indexPath row];
    cell.senderLabel.text = [messageList objectAtIndex:row];
    cell.messageTitleLabel.text = [messageList objectAtIndex:row];
    cell.channelLabel.text = [channelList objectAtIndex:row];
    
    return cell;
}

8. 让UITableViewCell背景透明

[self.postsTableView setBackgroundColor:[UIColor clearColor]];

9. 让UITableView分割线强制顶头显示

[self.postsTableView setSeparatorInset:UIEdgeInsetsZero];


10. 将UIImageView变为圆形且加上阴影,此例中imageView的大小为100*100,圆角设为高度的一半即可。另外需要将imageView放到container(UIView)中,再apply shadow layer

CALayer *layer=logoImageView.layer;
layer.masksToBounds=YES;
layer.cornerRadius=50;
layer.borderColor=[UIColor whiteColor].CGColor;
layer.borderWidth=3;
    
logoImageViewContainer.backgroundColor=[UIColor clearColor];
logoImageViewContainer.layer.shadowColor=[UIColor darkGrayColor].CGColor;
logoImageViewContainer.layer.shadowOpacity=0.8;
logoImageViewContainer.layer.shadowOffset=CGSizeMake(3, 3);
logoImageViewContainer.layer.shadowRadius=3;
logoImageViewContainer.layer.shadowPath=[UIBezierPath bezierPathWithRoundedRect:logoImageView.bounds cornerRadius:50].CGPath;




(未完待续)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值