Make UIView and subviews translucent as one layer, not individually - iphone

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).

Related

Make bottom part of UITextField(UIScrollView) transparent

Here's a good example that sums it up:
This is a UITextField that contains long text, so the user is able to scroll down to view the rest of the text.
How can I make the bottom rows appear "transparent"?
UITextField only allows setting global text properties (like color, font size, etc).
The trick is to create a CALayer containing a gradient and use it as mask layer of your UIView's layer (alpha values of the mask layer will be used.) see this answer: UIView border with fade or blur effect
This will help you.Not sure but some functionality like you want.
Hope this helps you.
All the best !!!

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.

UIView: Rounded Corners Without Performance Issues

I am using an AQGridView to display my data in a grid on iPad. Every cell is a UIView subclass and typically, there are 18 cells displayed simultaneously.
I would like to add a round corner to these cells, so I set the cornerRadius property of the relevant layers (i.e. the layer of the main UIView and of one subview). However, this results in performance issues and the scrolling is not smooth any more. When using other CALayer properties, such as shadowOpacity, this does not happen.
Are there any other ways to add a rounded corner (apart from using an image)? Or am I doing something wrong?
I also saw a major performance hit when using cornerRadius on the layer of a view that contained a UIImageView subview. Rasterization solved that problem: view.layer.shouldRasterize = YES;
It could be where you're placing the setCornerRadius call. Make sure it's somewhere that only gets called once, not, for example, in a drawRect method.

Unable to add oversized button in UIToolbar

I have a UIToolbar in IB with a custom UIBarButtonItem that is set to an image. The image height is larger than the UIToolbar height. The image does not load for some reason. Attached is a screenshot.
You should avoid using subviews that are larger than the parent view - even if it does work and draws the view outside of the bounds, you cannot always count on it because the clipping is skipped for performance reasons and depending on the drawing order the overlapping part of the subview might be covered later. Second problem is that only the part within the frame of the superview is able to handle the touch events.
As to why you don't see your image, it's probably a different problem, I doubt it has something to do with it going outside the frame. Post your code to get more feedback ;)

What's the best way to handle landscape/portrait differences in IB?

I have a view that supports landscape and portrait viewing, with the controls all moving around when you switch from one to the other. I'm currently doing this by setting the .center of each one of my controls when the user rotates the phone. The problem is that this is tedious, and requires a lot of code, and seems to defeat the purpose of using Interface Builder in the first place.
My question is: is there a way in Interface Builder for one view to support multiple looks (one for landscape one for portrait)? If not how do other people do this with IB? Do you set up 2 views?
Edit: Just to clarify my landscape and portrait views look different, I don't want a straight transform, I actually display the data differently in landscape mode
When necessary, I add UIView objects to the view in IB which I make hidden. Give it a nice background color so you can see it, and send it all the way to the background. Then use that view's frame when you need to set the frame of an object. If you have a lot of them, you might consider using UILabel instead, so you can give it a visible name in IB.
If you're worried about memory issues, just remove all these extra UIViews in ViewDidLoad and just store their frame values in member CGRects. This only works of course if you don't have any of the views auto-resize or reposition on rotate, which you probably shouldn't anyway, in this case. I do this for resizing/repositioning for any reason, not just when the screen rotates.
I'm not 100% sure if it's possible, but have you considered using different view controllers for landscape and portrait?
The AutoSize attributes of IBOutlet objects in the Size Inspector of IB (command 3) give some pretty nice options for auto-stretching and positioning of items. You can control L/R and T/B screen positions and relative width and height. You can't get full control of the layout, but most of the basic operations are there.
The only way one view can support multiple orientations in IB is to set the autosizing mask of components to either scale and/or anchor to edges. To design a totally different layout for each orientation you need to design a portrait and landscape view separately (each in its own XIB) and switch between them programatically.