开发者

Center [UIColor colorWithPatternImage]?

I couldn't find anything on how you can center the 'image' when you use (maybe you can't):

[self setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]];

Setting my [self setContentMode:UIContentModeCenter]; doesnt help.

Do I have to man开发者_运维问答ually draw the image (either in drawRect or set the content of the CALayer? Which one if preferable?


I think you're on the wrong path here: you create a UIColor from a pattern (pattern already implies this is a repeating image). All in all- you can't have your pattern not repeat and centered.

If you just want simple image as background of your UIView, just add it as a subview and center it.

UIImage* img = [UIImage imageNamed:@"yourfile.png"];
UIImageView* imgView = [[UIImageView alloc]initWithImage: img];

[yourUIView addSubview: imgView];
imgView.center = CGPointMake(yourUIView.frame.size.width/2, yourUIView.frame.size.height/2);

Now - add more subviews to your "yourUIView" view and they'll show on top of the image - thus the image becoming the background.

So... no need to draw anything yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜