简体   繁体   中英

Changing background images of UIView

I have a class :

@interface UIExView : UIView {
.......
}

In another class, UIExView is defined as following:

IBOutlet UIExView* exView;

exView is connected to an View in XIB.

I set background image of exView as:

UIColor* bgrColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed: backgroundImageName]];
exView.backgroundColor = bgrColor;

Now I want to change another image as background of exView. I do the same things:

UIColor* newBgrColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed: anotherBackgroundImage]];
exView.backgroundColor = newBgrColor;

It work well on simulator(background image is changed to the new one) but it does not work on real device. Pls, share your experience, thanks.

Maybe you can try to add an UIImageView in the UIExView, make an IBOutlet to the UIImageView and then make some methods that allows you to change the background image? Just an idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM