How to set background image of a view?

后端 未结 7 1250
梦如初夏
梦如初夏 2020-12-04 16:35

I am a beginner at Obj-C/Cocoa Touch/iPhone OS.

I wish to have a background for my app with different images everytime the the view is called.

Say I have 10

7条回答
  •  -上瘾入骨i
    2020-12-04 17:35

    You want the background color of your main view to be semi-transparent? There's nothing behind it... so nothing will really happen however:

    If you want to modify the alpha of any view, use the alpha property:

    UIView *someView = [[UIView alloc] init];
    ...
    someView.alpha = 0.8f; //Sets the opacity to 80%
    ...
    

    Views themselves have the alpha transparency, not just UIColor.

    But since your problem is that you can't read text on top of the images... either:

    1. [DESIGN] Reconsider the design/placement of the images. Are they necessary as background images? What about the placement of the labels?
    2. [CODE] It's not exactly the best solution, but what you could do is create a UIView whose frame takes up the entire page and add some alpha transparency to it. This will create an "overlay" of sorts.
    UIView *overlay = [[[UIView alloc] init] autorelease];
    overlay.frame = self.view.bounds;
    overlay.alpha = 0.2f;
    [self.view addSubview:overlay];
    ... Add the rest of the views
    

提交回复
热议问题