Setting 2 different backgrounds for a view - iphone

I have a view, which is divided into 2 parts. On the top half of the view I want a blue background and on the bottom half I want a transparent background. I am not sure if it can be done.
Any suggestions will be appreciated. Thanks

There are multiple ways to do this. By far the easiest is to simply create a subview in the top half of the view with a blue background. Other methods include adding a sublayer or overriding drawRect with custom drawing code.

if you only want to create a single view then you have to create a image file with 2 parts
upper part is blue and bottom half is transparent
else you need to create two view with different background

Related

iOS: how to adjust positions of UI elements one by one properly by IB when some of them may change size?

For example, on a UIView, from left to right there are three buttons:,button1,button2,button3.
When button 1 become wider, such as its width become twice as its original width, is there any interface builder way that can make button2&3 move right automatically?
sorry for I didn't make my question clear.
I mean such kind of size change: I push button1, then I change it's frame in my code, not caused by the change of text in butotn1. I want button2&3 to move right automatically, keeping the width of the gap between button 1 and 2 unchanged.
Thanks everyone.
IB can be used only for initional positioning of views.
True, you can also define autoresizing masks of the views but that's about it.
Any additional laying out should be done in code.
I could be wrong, but I don't know of any way you can do this in IB. It's pretty straight forward in code though, just link the buttons to some IBOutlets and check the sizes of the images of the buttons (myUIImage.size), then adjust the frames of the buttons (do it in viewWillAppear).
Seen your edit - if you're adjusting its size using code, adjust its position too.
If your buttons are in a row at the bottom of the screen, consider using a UIToolBar. Its UIBarButtonItem objects automatically adjust to fit each other's width changes. For more generic cases, you'll need to recalculate positions and sizes as in Franklyn Weber's answer.
Yes - by using autoresizing masks. If you allow the margins to be flexible (no red lines connecting the frame to the superview's frame) and allow flexible width and height, the buttons will size and move proportionally.

Fill iPhone Screen With Translucent Mask EXCEPT For One Area

I already have a view box showing the user where to center the text they would like to analyze, but I would like to fill the rest of the screen with a translucent gray mask. Unfortunately I can't simply pre-render what I want (as shown in the image) in Photoshop and just add it to the project because I need the view box to remain programmatically added separately. Is there a way to add color to a view in all areas except a designated area?
Why not just add 4 translucent views (fill them with black and set their alpha property to 0.5 for example) on top of the view? One on top, bottom, left and right of the area you want translucent?
That shouldn't be too hard to do, you can just modify the size of the views based on where you want the box to be.

Make UIView and subviews translucent as one layer, not individually

When setting the alpha of a UIView (on iOS) it sets each subview to the same value, but composites them with that alpha on top of their respective superviews. So the subviews are blended with their superviews.
I don't want this to happen. I want the opacity to be applied to the UIView as a whole, not to each individual view. I want to achieve the same effect as, say, CSS3's opacity, or applying opacity to a group of layers in Photoshop, rather than to each layer individually.
The complexity however is that in this UIView is a UITableView and others that need to be interactive. And it's not viable to have the view that is supposed to be behind this view on top instead.
My question is: What's the best way to achieve this?
Thank you!
Alec
There's a 'Renders with group opacity' setting in Info.plist
Documentation here:
http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
(Search for the mentioned setting).

What is the best way to implement a widget like this in iPhone SDK?

alt text http://img696.imageshack.us/img696/4453/screenshot20100505at125.png
At first we thought of have a back bar and a front bar and simply grow the front bar as the bar progresses. But then we realized that the front bar cannot "stretch" because it has a flat end, and the flat end will be taller than the back bar when it reaches near the end.
How would you implement this bar in the iPhone SDK?
I would do the same as Sophtware but with a bit more sophistication, since the background below the progress bar also seems to be an image view, having a bit of gradient on right side.
From bottom to top, I would have:
1) at the very bottom - background of the progress bar, stationary. It can be larger than the progress bar area since it will have stuff sitting on top of it.
2) the progress bar rectangle with border, shadow, gradient etc - as Sopthware says, you would slide this left and right for desired "progress"
3) the top layer - the bezel around the progress bar, with a hole (transparent area) in the middle, from where both the progress bar and background would be.
EDIT: you mentioning the background being UIToolbar changes things a bit. The easiest way implementation-wise would actually to produce all the possible states of the widget as one monolithic image. At runtime, you would simply swap the images. The widget is sufficiently small that this would not have an impact on the app size, and should be fine if you don't want to do complex animation or anything like that.
There are other ways of doing it that would involve breaking the image into pieces, but as you mention, those will be more dependent on the UIToolbar color. Producing it as a monolithic image will work with any toolbar color.
You could use two image views. The top one would be everything with the progress part knocked out, which would have that area set to transparent. The second image view would be rectangle of the entire progress portion. Then just slide the progress part under the top view to get the desired affect.

UIPickerview customisation

I would like to do some customization of the UIPickerView.
End Goal: have a picker view rotating a few icon sized images.
firstly i would like to change the black/grey boarder surrounding the spindle to a transparent colour. i.e. [UIColor clearColor];
Then shrink the picker view down so it is relatively small, (probably around 40 x 40 pixels) Experimenting with this is IB did not make it seem easy.
Finally change the view returned to the picker for each section. This i think is easy with
pickerView:viewForRow:forComponent:reusingView:
The rest, not sure if it is possible or if i am going to have to delve into some of the core animation/graphics (or find a different way to do what i want).
UIPickerView is not customizable. At all.
You'll have to go custom for what you want.
Perhaps the easiest way would be to mess with an UIScrollView with vertical pagination enabled, and try to get it to act like you want. Maybe overlap an UIImageView with it and wrap the whole thing up in a custom view.
You can also "customize" the outer bezel of the picker by simply placing a UIImageView over the top with a hole cut out for the working parts. Apple does this with the Clock app.