导航栏背景色改变

直接贴代码


//设置导航栏背景色

    UIBarButtonItem *barItem = [UIBarButtonItem appearance];

    

    UIImage *bg6 = [UIImage imageWithColor:UIColorFromRGB(78157225size:CGSizeMake(144)];

    UIImage *bg7 = [UIImage imageWithColor:UIColorFromRGB(78157225size:CGSizeMake(164)];

    if (!IOS7)

    {

        [navigationBarAppearance setBackgroundImage:bg6 forBarMetrics:UIBarMetricsDefault];

        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;

    }

    else

    {

        [navigationBarAppearance setBackgroundImage:bg7 forBarMetrics:UIBarMetricsDefault];

    };

    

    

    //UIColorFromRGB(255, 255, 255)

    [barItem setTitleTextAttributes:@{

                                      NSForegroundColorAttributeName:[UIColorwhiteColor],

                                      NSFontAttributeName:[UIFontsystemFontOfSize:14]

                                      }forState:UIControlStateNormal];

    

    

//设置文字颜色

    NSDictionary *textAttributes = nil;

    

    if ([[[UIDevice currentDevicesystemVersionintegerValue] >= 7.0) {

        textAttributes = @{

                           NSFontAttributeName: [UIFont boldSystemFontOfSize:18],

                           NSForegroundColorAttributeName: [UIColor whiteColor],

                           };

    } else {

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0

        textAttributes = @{

                           UITextAttributeFont: [UIFont boldSystemFontOfSize:18],

                           UITextAttributeTextColor: [UIColor whiteColor],

                           UITextAttributeTextShadowColor: [UIColor clearColor],

                           UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],

                           };

#endif

        

    }

    [navigationBarAppearance setTitleTextAttributes:textAttributes];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在HTML中,可以使用CSS来控制导航背景,并使其根据浏览器页面的伸缩而改变。 首先,在HTML文档中,我们需要创建一个导航的容器元素,可以使用`<div>`标签来实现。可以将导航容器放置在网页的适当位置,比如页面的顶部或侧边。 然后,在CSS样式表中为导航容器添加样式规则。我们可以使用`background-color`属性来设置背景。为了实现背景根据浏览器页面的伸缩而改变,我们可以使用CSS3中的响应式设计的单位,比如`vw`。 `vw`表示相对于视口宽度的单位,当浏览器窗口的宽度改变时,元素的样式也会相应地调整。 例如,我们可以使用以下代码设置导航容器的背景: ```css .nav-container { background-color: #8BC34A; /* 初始的背景 */ width: 100%; /* 设置宽度为100%以适应视口的宽度 */ padding: 10px; /* 设置内边距以增加容器的高度 */ } @media (max-width: 768px) { /* 当视口的宽度小于或等于768px时,修改背景 */ .nav-container { background-color: #2196F3; /* 修改后的背景 */ } } ``` 在上述代码中,我们首先为导航容器设置初始的背景为`#8BC34A`。然后使用`width: 100%`将其宽度设置为100%,以适应浏览器窗口的宽度。 接下来,使用`@media`查询来指定当视口的宽度小于或等于768px时的样式。在这种情况下,我们将背景修改为`#2196F3`,可以根据需要自行调整颜值。 这样,导航容器的背景将根据浏览器页面的伸缩而自适应地改变,使得导航在不同的屏幕尺寸下有更好的可读性和可用性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值