If you're just using solid colours, then simply use a UIView
and set the backgroundColor
property. Using an image for this purpose is unnecessarily complicating things, besides, a UIImageView
is a subclass of a UIView
, so the only added functionality is going to pertain to things you don't need.
So now that we've settled on using UIViews
instead of images, you don't have to worry about the UIViewContentMode
anymore (or the Scale to fill nonsense). Simply change the size
and origin
properties of your views accordingly.
An example of using Views instead of Images for this purpose: (I can't guarantee syntax as I'm not writing this from my Mac)
UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(0,0,280,20)];
UIView *orangeView = [[UIView alloc] initWithFrame:CGRectMake(0,0,280,20)];
greenView.backgroundColor = [UIColor greenColor];
orangeView.backgroundColor = [UIColor orangeColor];
CGRect newGreenFrame = greenView.frame;
newGreenFrame.size.width = newGreenFrame.size.width * 0.75;
greenView.frame = newGreenFrame;
This is a good way of initializing and changing the frames of UIViews
. There are other, shorter ways of doing it but this allows for easier-to-read code.