您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

UITabBar的圆角

UITabBar的圆角

嘿,我使用了tabBar的简单属性,即backgroundImage。

因此,我在didFinisLaunchingWithOptions中添加了appDelegate:

let tabBarController = window?.rootViewController as! UITabBarController
    let image = UIImage(named: "bar")
    let tabBarImage = resize(image: image!, newWidth: tabBarController.view.frame.width)
    tabBarController.tabBar.backgroundImage = tabBarImage

和我的自定义方法来更改图像的大小:

func resize(image: UIImage, newWidth: CGFloat) -> UIImage {

    UIGraphicsBeginImageContext(CGSize(width: newWidth, height: image.size.height))
    image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: image.size.height)) // image.drawInRect( CGRect(x: 0, y: 0, width: newWidth, height: image.size.height))  in swift 2
    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    return newImage!
}

我使用了png图像作为背景,与您发布的图像相同,但是具有清晰的 颜色而不是黑色。

希望这可以帮助

其他 2022/1/1 18:14:41 有218人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶