How to prevent UIView background from rotating? [duplicate] - objective-c

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I rotate a UIView without the black bars?
I want the labels on my UIView to rotate (and they do) but I've set the background to a color other than black. When I rotate you can see the view's rectangle rotate against a black background. How can I keep the UIView's background still yet allow the rest of the subviews to rotate normally? And what is that black background behind everything? Do I have access to it?

I'm not sure I fully understand the question. What I think your question is (if I'm misunderstanding please clarify where I'm getting the question wrong):
You have a UIView that is the same size as the device's screen.
You want to rotate that view.
When you rotate that view the background of the view's parent view can be seen.
I think the only ways to resolve this are either:
A) Make the view you're rotating larger than the screen so that when you rotate the parent view isn't visible. If you do this make sure the parent view isn't set to clip it's subviews otherwise you won't see any difference after resizing.
OR
B) Make the parent view's background color match the color of the view you're rotating. If you don't want to permanently alter the background color of the parent view you can always change the color when you start the animation and revert to the original color when done.
P.S. - I think the "black background behind everything" is the background color of your app's UIWindow. If you want to change that you can do the following (assuming your app delegate has a window property defined but if you used one of the standard Xcode templates to create your app it should):
UIWindow* window = [[UIApplication sharedApplication].delegate window];
[window setBackgroundColor:<Some UIColor>];

Related

How can one draw a background in the elastic portion of an NSScrollView?

I have a custom NSScrollView with elasticity turned on in both orientations. Currently I just get a black (ugly) background when I scroll/bounce into this elastic section. How do I control what gets drawn into this section?
For a start, I would just want to be able to set the background colour of this section to a specific colour.
Things I have tried that do NOT seem to work:
Using the background property of the NSSCrollView - it doesn't seem to do anything which is also strange?
Setting the custom NSScrollView.wantsLayer = true and then choosing an appropriate CGColor => also no effect
Adding an independent subView with a background color to NSScrollView that fills it vertically and horizontally (even tried overfilling by using negative leading spaces) => no effect
Trying to use constraints to make the contentView bigger than the NSScrollView => no discernible effect
Making the documentView bigger => it just made the documentView extend for said amount (this was silly, but one does get desperate!)
Setting the background on the NSClipView as suggested in a comment below => no effect
Well if at first you don't succeed (and nobody has answered your question on SO yet)...
What worked is to add a subview to the NSClipView (not the NSScrollView) constraining it to be adjacent to the documentView where the elasticity is arising. That's all...
Add a subview to the scrollView which is not the documentView, and this view will not scroll or magnify. Constrain that view to the edges so that it is the full size of the scrollView

Adding a UIView as a subview to UIImageView

I am working on creating a color picker for "iOS". I am using this project, since it does what i want: "This"
I want to create a moveable circle (UIView) on top of the palette (UIImageView).
What I want to do is, while users move the circle, take the touch point and call the method getPixelColorAtLocation(); and change the background color of the circle to the color on current point. (Seen on most of the color palette/wheels)
The method getPixelColorAtLocation() is available on a child view. I created a circle with UIView on parent view, the problem is I cant call to getPixelColorAtLocation() from parent view.
My question is, Is there anyway to add a UIView as a subView to UIImageView. If I cant, what choices do I have to achieve what I want?
Yes you can do this.
[myImageView addSubview:sampleView];
An image view is just a subclass of UIView, so you can add subviews to it however you'd like. If there's a reason why you can't do so, then you can always make it a subview of the image view's superview, move it to the front, and then use convertPoint:toView: to convert to the image view's coordinate system, then get the pixel color.

How to put background for UITableViewController

I wanna do something like THIS in my ipad application, what is the best way to do the followings:
The shadow under the upper bar.
The padding for the papers (top, left, right & bottom)
The background (as a notepad) : please think about the cells: they must still scrolled inside the paper and cropped before reaching to the paper bottom edge.
I'm looking for the optimal solution that avoids overriding as much as possible.
EDIT :
I tried to use UIViewController (with UITableVIew and has the delegate methods) inside UISplitViewController, And I tried adding UIImageView at the top of the table but this view will scroll with the cells and it'll hide when I scroll down. I tried to use viewForHeaderInSection function also for upper shadow (under the bar) but what about the papers bottom edge (what if I put one image including the shadow and the papers bottom edge and has the padding as a background for the UITableView or UITableViewController, and change this image when rotate to the portrait orientation? is this a good and possible solution?)
My guess:
Create the background in an image editing app
Cut 4 images, for header, footer, left and right sides
Create a UIViewController with 4 UIVIews and add the correct images as background
In the middle of all 4 add a UITableView
This way the images won't move and if you position the UIViews with the background properly, your TableView will scroll inside the notebook (assuming you are trying to create a notebook)
If you app is iOS 6.0 only, autolayout will be a great help. Check apple developer video on it to learn how to use this feature: WWDC 2012 Session 232 - Auto Layout by Example
One easy way to do this is from the xib:
1. In xib create image .On image view you can put background whatever you want as a image.
2. create table view above the image view and set table view background color as a clear color.
This will do it.

Transparent NSWindow but with standard border and shadow [duplicate]

This question already has an answer here:
Holes in NSView or NSWindow
(1 answer)
Closed 6 years ago.
I want to have a more or less standard NSWindow with a toolbar and all that, but I want the content view to be transparent so that I can see through it. At the same time I want to keep the light gray outline of the window and also it's shadow. BUT I want to avoid the "inner" shadow I get from the toolbar inside the content view area.
What I have tried so far is just to set the window background color to a semi transparent color and also set opaque to NO. The problem is that the window border fades away with the alpha of the background itself, and the more transparency I have on the background, the more the shadow of the toolbar shows up within the content view.
Generally, the window shadow and border changes depending on the transparency of the content view, which I totally understand. But I want a behavior where it keeps the border and shadow just as if it was a completely opaque window, and then I want the content view area to be transparent.
I am not sure what I need to do conceptually to make it work. Maybe I have to draw the window border myself, maybe not. Maybe I need to draw the shadow myself, or maybe not.
Is there anyone that know how to build this? I don't need exact code details, but rather what parts I need to do custom..
I appreciate any input!
I dont't know if this is of any value for you after all this time but try:
[aWindow setOpaque:NO];
[aWindow setBackgroundColor:[NSColor clearColor]];
Subclass the NSView class, override the drawRect:(NSRect)dirtyRect method and set the color of the view as clearcolor, now set the class of your content view as the Subclass of NSView.

Rounded corners on NSTableView

I have a custom view subclass similar to NSBox that draws a rounded box background. The problem is that if I place a view like an NSTableView in the box view, it does not clip to the rounded corners. Is there any way to round the corners of NSTableView and its parent scroll view?
I haven't tried this with a table view but have with other controls.
In a subclass of NSTableView (or whatever view/control you want to clip)
Override drawRect:
Create an NSBezierPath with the shape you want (probably appendBezierPathWithRoundedRect:xRadius:yRadius: just remember to use the view's bounds as the size)
Send the path the addClip message to add that shape to the view's clipping path
Call super's drawRect:
If the table view has a header you may need to clip the top corners by subclassing NSTableHeaderView. And if you have scrollbars you may have to do the same thing to them except only clip certain corners. Hopefully you don't have scrollbars because I doubt that would look right. Basically you want to clip the view/control that draws that part, clipping the parent will not cause subviews to be clipped.
If you look at Apple's Welcome to Xcode window they get away with it by drawing a custom header at the top and a text block at the bottom so they don't have to round the table view itself. If you can do something like that I would.