自定义UITabBarController的tabBar背景图片

  • Post author:
  • Post category:其他


新建一个类继承UITabBarController:

– (

id

) init

{


self

= [

super


init

];


if

(

self

) {


//


方法一



UIImageView

*img = [[

UIImageView



alloc


]


initWithImage


:[

UIImage



imageNamed


:


@”bg.png”


]];


img.

frame

=


CGRectMake


(


0


,


0


,


self


.

tabBar

.

frame

.

size

.

width

,


self


.

tabBar

.

frame

.

size

.

height

);


img.


contentMode


=

UIViewContentModeScaleToFill

;



//img.frame = CGRectOffset(img.frame, 0, 1);


[[


self



tabBar

]

insertSubview

:img

atIndex

:


0


];

[img

release

];


//


方法二


CGRect

frame =

CGRectMake

(

0

,

0

,

self

.

view

.

bounds

.

size

.

width

,

49

);


UIView

*view = [[

UIView


alloc

]

initWithFrame

:frame];


UIImage

*tabBarBackgroundImage = [

UIImage


imageNamed

:

@”bg.png”

];


UIColor

*color = [[

UIColor


alloc

]

initWithPatternImage

:tabBarBackgroundImage];

[view

setBackgroundColor

:color];

[color

release

];


[[


self



tabBar

]

insertSubview

:view

atIndex

:


0


];

[view

release

];

}



return


self

;

}



版权声明:本文为xbiii3s原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。