UIPickerView background color not changed? - objective-c

I want to change the picker view bakground color. I try this way but not worked.
doublePicker.backgroundColor = [self RGBColorR:85 G:17 B:92];
- (UIColor *)RGBColorR:(double)red G:(double)green B:(double)blue {
return [UIColor colorWithRed:(red/255.00) green:(green/255.00) blue:(blue/255.00) alpha:1.00];
}
I want to do picker view like in picture. How can I do this? Thanks for your reply.

you can add subviews over certain areas of your pickerview..
use:
[picker addSubview: coverView]; //adding subviews to different area of the picker
you're going to find yourself playing with alot of CGRect to get thing to fit properly. If you want to change the entire thing you're going to have to override some methods that handle the touch events etc..
this tutorial might help you create a custom picker
https://developer.apple.com/iphone/library/samplecode/UICatalog/

You cannot change the appearance of UIPickerView, even the size, it's the most unchangeable UI element in iOS. Best you can do is build custom by yourself, using UIScrollView with paging enabled.

Related

When NSTableview Load second time its customcell Subview's change it's position how to solve

I am new for cocoa OSX application might be this question is simple but i try my best to find out this issue and at the end i asking question here.
I am creating NSWindowViewController and in side it i Used NSTableview with Customcell. In customeCell i used NSView (customView) and all Cell IBOutlet put in side NSView. When First time that NSWindowViewController load that show fine but after close the window and again i open it. its NSTextField IBOutlet change its position top to bottom of the cell.
I try to find this some property change but did not fix it i attach its screen example what was happen with my cocoa osx Application.
I notice that this happen when i used following code for setting NSview's background color from property Inspector i setting NSView Core animation like.
And set background color in viewForTableColumn like:
cellView.bgview.layer.backgroundColor = [NSColor whiteColor].CGColor;
Color set properly and all working fine when i reload table view that top label going to bottom and that will display revers UI order for cell as i show in my question.
And i tested with if i remove NSView setting background color code as i mention above then working perfect no re-order and all things. I am not using Auto-layout.
So after then i create custom subclass of NSview for setting color like following:
- (void)drawRect:(NSRect)dirtyRect {
[[NSColor whiteColor] setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
// Drawing code here.
}
I remove my old code and use this one for setting background by creating NSView subclass and my issue fix.

Draw Over Image

I'm working on some drawing code. I have that portion working great.
I want to draw over an image, but I want to still be able to see the detail of the image, the black lines, etc.
What I am working on is making a transparent UIImageView that holds the image.
I'm not sure how to get this set up properly though.
Should this be added above the other UIImageView that I color on or below it?
Here's what I have so far:
- (void)viewDidLoad
{
[super viewDidLoad];
topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 46, 320, 370)];
[topImageView setImage:[UIImage imageNamed:#"imagesmall.png"]];
topImageView.alpha = 1.0;
topImageView.layer.opacity = 1.0;
topImageView.layer.opaque = NO;
[self.view addSubview:topImageView];
[topImageView release];
}
Thoughts anyone?
Yes, you can draw views over other views. They are drawn in the order that they're added as subviews, unless you reorder them after that.
You may need to set the opaque property for some views (this is distinct from and overrides their layer opacity), and set their backgroundColor to nil. UIImageView seems to be transparent by default, as long as its image is; some other UIView subclasses are not.
So, just what is your overlay going to be? If you just need to display one image over another, what you have here seems to work already. If you need to draw some lines programmatically, you'll need to do this:
Create a subclass of UIView.
Implement its drawRect method to display the content you need.
When you add your custom view on top of the background image, make sure it is not opaque and has no backgroundColor.
A common problem here is to find that your foreground is working, but the background isn't being loaded properly. To make sure the background is there, set the alpha of the foreground view to 0.5. You won't want to do that in production, but it will allow you to verify that both views exist.

Changing color of an MKOverlay that has already been added to a mapview

I have some MKOverlays(actually they are MKPolygons) that are loaded as soon as the map shows up. I would like to change their color dynamically. The only way I can see of doing this, is to remove the overlay then add it back with the new color. Is there a better way to do this on the existing overlay?
I am brand new at objective-c/xcode/ios ... so please be gentle :)
Your mapView has a method for getting the renderer object for a given overlay. You can then use the renderer to change the color of your overlay.
if let renderer = mapView.rendererForOverlay(overlay) as? MKPolygonRenderer {
renderer.fillColor = UIColor.redColor()
}
Leave out the optional cast to MKPolygonRenderer if you're not looking for an MKPolygon overlay.
(I realize this is a rather old question, but I just stumbled across it and found my solution 😊)
It is important to remember that much of MapKit has different objects (MKPolygon, MKCircle, MKShape) to hold the data related to drawing a view (MKPolygonView, MKCircleView, MKOverlayView, etc.) In many cases you want to get a reference to the view object so you can then set the background color. i.e.
MKOverlayView *anOverlay; //You need to set this view to the object you are interested in
anOverlay.backgroundColor = [UIColor redColor];
[anOverlay setNeedsDisplay];
If your object is an MKPolygon, you should determine the MKPolygonView it is being drawn into an then set the fillColor property and redraw the object by calling setNeedsDisplay:
MKPolygonView *theView;
theView.fillColor = [UIColor redColor];
[theView setNeedsDisplay];

Custom Keyboard: inputView: how to change the Keyboard size?

I implemented the textfield with a custom keyboard with the "setInputView" function.
But i have a problem: my keyboard frame is not a standard iphone keybord frame.
The question is:
How can i change the size of my custom keyboard?
I know some functions like: UIKeyboardFrameBeginUserInfoKey, ..etc.
Please Note:
The iPhone keyboard frame is = 0,264,320,216
My custom keyboard frame is = 0,0,320,460
Hoping for your kind collaboration,
Best regards...
P
It turns out that the default behaviour of the custom input view that you assign to the UITextField's property is to resize the view to the same frame as the default keyboard. Try setting (I use the name InputViewController for my input view, but you can use whatever you want):
inputViewController = [[InputViewController alloc] initWithNibName:#"InputViewController" bundle:nil];
inputViewController.delegate = self;
inputViewController.view.autoresizingMask = UIViewAutoresizingNone; // This is the code that will make sure the view does not get resized to the keyboards frame.
For more detailed information, you can look at this link, which is provided by Apple.:
If UIKit encounters an input view with an UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard.
Hope that Helps!
To set the keyboard inputView with the same size as the native keyboard just do this:
inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
To set your own frame do this:
inputView.autoresizingMask = UIViewAutoresizingNone;
From Apple:
You have a lot of flexibility in defining the size and content of an input view or input accessory view. Although the height of these views can be what you’d like, they should be the same width as the system keyboard. If UIKit encounters an input view with a UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard. There are no restrictions on the number of subviews (such as controls) that input views and input accessory views may have. For more guidance on input views and input accessory views, see iOS Human Interface Guidelines.
I had the same problem. I solved it by registering for UIKeyboardDidShowNotification (UIKeyboardWillShowNotification did not work, unfortunately) and then changing the view size after the keyboard was shown. However, it still had the white box on top of the keyboard when it was moving up. This worked fine for me because it is coming in over a UITextView with a white background. If you were coming in over any other colored objects, however, it would look a little ugly before the view was properly resized. You can solve that by setting the background color to clearColor.
// Add this while initializing your view
self.backgroundColor = [UIColor clearColor]; // Needed because we can't resize BEFORE showing the view. Otherwise you will see an ugly white box moving up w/ the keyboard
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
CGRect rect = self.frame;
rect.size.height = 164;
self.frame = rect;
}
Also if you're using a UIViewController to design your inputView, don't use the UIViewController.view... it seems to have a lot of problems getting resized incorrectly on rotate regardless of the AutoresizeMask.
What worked for me was to take my existing UI and use Editor > Embed In > View. Then create a new outlet, and pass that outlet as the inputView. Suddenly the resize on rotate bugs disappeared.
For me msgambel's solution didn't work. But the approach right, I was playing with the inputView's autoresizingMask. Former I had different setting, but the right way to avoid white extra space over the custom keyboard is:
I applied this just for the outermost view.

UINavigationBar autoresizing

In my app, I got a UINavigationController. Unfortunately, when I rotate the device and the interface orientation changes, the UINavigationBar doesn't change its height. In other iPhone applications, such as the Contacts.app, the navigation bar gets slightly less tall in landscape mode. It must be built-in, because if you take the navigation sample app from the XCode menu and add interface orientation to it, it does change the navigation bar's height properly.
How can I make the navigation bar resize like it does in all other iPhone apps I've seen?
I've done a little testing, and although I don't like the method, it's quite easy to do.
Having looked for a private method that may have worked, I couldn't find one. All I found was:
#property BOOL forceFullHeightInLandscape;
- (BOOL)isMinibar;
There is no setter for -isMinibar, so we can't set that. I guess that it returns a value based on its height. Also, forceFullHeightInLandscape was set to NO, however it still didn't adjust its height.
While changing the autoresizingMask to include UIViewAutoresizingFlexibleHeight, the view did resize to be smaller, but now it was too small. However, -isMinibar suddenly returned YES. So that made me think of just letting the view resize itself, adjusting it to the right height.
So there we go, a method that works, even without private API calls:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.navigationBar performSelector:#selector(sizeToFit) withObject:nil afterDelay:(0.5f * duration)];
}
One thing you'll have to deal with is that the views below the bar won't get adjusted to the smaller bar, so that there will be a gap between the bar and the views below. Easiest way to solve this is to add a container view, just like the case with a UINavigationController. You'd come up with something like:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self performSelector:#selector(resizeViewsForNavigationBar) withObject:nil afterDelay:(0.5f * duration)];
}
- (void)resizeViewsForNavigationBar {
[self.navigationBar sizeToFit];
// Resize containerView accordingly.
CGRect containerViewRect = self.containerView.frame;
containerViewRect.origin.y = CGRectGetMaxY(self.navigationBar.frame);
containerViewRect.size.height = CGRectGetMaxY(self.view.frame) - containerViewRect.origin.y;
self.containerView.frame = containerViewRect;
}
I think the behavior you want only happens when a navigation controller ( which represents the bars (navigation or toolbar)), is added to the window in the app delegate or presented by a tab bar, etc.
You can add a navigation bar via IB or code, it doesn't mean you have a navigation controller. My opinion is, create a navigation controller and initialize it with the view controller you're working in. Probably when the view rotates, the nav bar will shrink a little, the way you like.
Hope this helps
Thanks to Joost I've added
#property BOOL forceFullHeightInLandscape;
to my custom UINavigationBar class. And set in :
-(id)initWithFrame:(CGRect)frame{
forceFullHeightInLandscape = YES;
Worked like a charm
Similar to Joost's answer, but putting the method in willAnimateRotationToInterfaceOrientation has a better animation effect than willRotateToInterfaceOrientation. (There's no animation delay)
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.navigationBar sizeToFit];
}
I just had this error as well, and although it's probably not for the same reason I'd like to post it here to help anyone else that goofs.
If you're overriding any willRotateToInterface methods, remember to call super
I blanked on that, but once I saw the accepted answer it came to me.
I think this one is kind of similar to you and they have the code snippet:
iPhone: UINavigationBar with buttons - adjust the height
I just tried a few things just within Interface Builder and Xcode and as long as you use the UINavigationBarController as RootViewController it works as described - getting smaller. Did you change any things within the Controller itself or in parts of how the Controller is loaded? Especially concerning the firing of events? I had some bad expiriences with the UITabBarController in terms of breaking the proper messaging and got some 'interessting' view side effects. Just a try and a guess.
(void)viewWillLayoutSubviews {
self.navigationItem.titleView.bounds = self.navigationController.navigationBar.bounds;
}