2016-06-30 5 views
0

丸いコーナーのUITabBarを作成したいと思います。 UITabBarに角を丸める方法がありますか?それは第二の絵の形をとるだろう。UITabBarの丸みのついたコーナー

アプリはtableViewから始まります。ユーザーがトピックをタップすると、そのトピックはTabBarコントローラに送信されます。

enter image description here This is the shape I want it to take

----- -----編集

これは私AppDelegateです:ねえ、私は単純なプロパティを使用

func application(_application: UIApplication, 
willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool{ 

    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 


    return true 
} 

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

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

return newImage! 
} 

enter image description here

答えて

0

backgroundImageであるtabBar

だから、私は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画像を使用し、あなたが投稿したのと同じですが、黒の色ではなく透明な色で表示されます。これは

+0

を助け

希望は「未解決識別子の使用:窓」と言う –

+0

はまた、それはあなたがそのエラーを取得することshould't –

+0

「UIiimageは 『引く』のないメンバーを持っていない」と言う、あなたはあなたが確かですコードを追加してください: funcアプリケーション(アプリケーション:UIApplication、didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool {} –

関連する問題