Customize Button in xcode5 - uibutton

I am trying to add a button into my app. I want the button to be just like the button used in old version of Xcode. that is round rectangular button. Is there a way to make my button in Xcode 5 as like in Xcode 4.5?

Add the following framework and import it in the header file.
import <QuartzCore/QuartzCore.h>
In your loadView method add following lines
yourButton.layer.cornerRadius = 10; // this value vary as per your desire
yourButton.clipsToBounds = YES;
Don't forget to change the text colour and button background.
This should do it.

in loadView:
[self.button.layer setCornerRadius:8.];
[self.button.layer setMasksToBounds:YES];

Related

How can i customize UIAlertAction in UIAlertController for iOS8?

I need to add image in Action sheet item using UIAlertController. I add using:
UIImage *image = [UIImage imageNamed:#"icon.png"];
[alertAction setValue:image forKey:#"image"];
And results as:
The problem is that:
I need the image & text to be centrally aligned and resize the height of Cancel button
How can i do that, please share some code.
Thanks!
Well, here is the Runtime Header file for UIAlertAction. You can neither change the frame of image nor you can change the height of Cancel button.
So what is the solution?
The only solution that I could figure is to make a custom view with UIVisualEffect and show/animate it like UIActionSheet. Basically you need to imitate UIActionSheet.
That said, I would like to welcome other solutions as well.

iOS 8 - Modal in Popover

I have a popover with TabBarController in it. In one tab there is a TableViewController with a list of names. And there is a plus button, that has a modal segue to AddCharacterVC for adding new names.
In iOS 7 I do it like this:
AddCharacterViewController *acvc = (AddCharacterViewController *)segue.destinationViewController;
acvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
acvc.modalPresentationStyle = UIModalPresentationCurrentContext;// so it does not take full screen in popover
And in AddCharacterVC I set content size like this:
- (void)viewWillAppear:(BOOL)animated {
CGSize size = CGSizeMake(320, 480); // size of view in popover
if (IDIOM == IPAD && [self respondsToSelector:#selector(preferredContentSize)]){
self.preferredContentSize = size;
}
And it works perfectly.
However, in iOS 8 modal view does not cover the whole popover, leaving TabBar visible. The user can tap on it or not, anyway modal view won't unwind properly.
I've tried:
setting acvc.modalPresentationStyle to UIModalPresentationOverCurrentContext
tried to set TabBar hidden
checked in storyboard that edges of TableVC extend under Bottom Bar and Bottom Bar in Modal View (AddCharacterVC) is set to none
All with no results.
Now the only thing I can think of is to try making modalPresentationStyleCustom and use UIPresentationController (I'm trying to do it now, but I haven't done it before). Am I missing something? Could there be other way to do it? Sorry, I cannot post images here yet. Many thanks in advance!
Ok, so I've set the modalPresentationStile to UIModalPresentationCustom, and used UIPresentationController - I've just copied code from WWDC-14's LookInside project and modified it a bit.
I'm not sure if it was the best solution, but it worked in my case.

iOS 8 UINavigationController disable Back Button

in my Navigation Controller I need to temporarily disable the back button. I know that it can be hidden using the following or something similar:
[self.navigationController.navigationItem setHidesBackButton:YES animated:YES];
But that is not what I need, instead I want the back button to be greyed out and non-responsive to user touch events. Is their a way to achieve this without replacing the default back button?
Thanks in advance!
To disable the back button, these commands would make it do what you want it to do:
Enable:
self.navigationController.navigationBar.userInteractionEnabled = YES;
self.navigationController.navigationBar.tintColor = [UIColor blueColor];
Disabled:
self.navigationController.navigationBar.userInteractionEnabled = NO;
self.navigationController.navigationBar.tintColor = [UIColor lightGrayColor];
Update:
As of iOS 7, there's also a swipe that you'll want to disable on the UINavigationBar.
// You wrap it an 'if' statement so it doesn't crash
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
// disable the interactivePopGestureRecognizer
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
This hides the back button, so it becomes unreachable for the user. And it disables the swipe gesture.
[self.navigationItem setHidesBackButton:YES animated:YES];
Swift:
navigationItem.setHidesBackButton(true, animated: true)
See more info in Apple's documentation.
I know this is quite old but I had this problem too.
In my case in one scenario I had to disable the back button and in another one I had to disable all navigation buttons. my solution was disabling the navigation bar in total in both scenarios:
self.navigationController.view.userInteractionEnabled = NO;
This won't show the buttons as disabled but will prevent touches.
Hope this will help
I believe that following should help:
self.navigationController.navigationItem.backBarButtonItem.enabled = NO;
UPDATE
Sorry guys, my belief didn't come true.
It seems that property backBarButtonItem is designed only for setting custom title or image for Back Button.
From documentation:
If you want to specify a custom image or title for the back button,
you can assign a custom bar button item (with your custom title or
image) to this property instead. When configuring your bar button
item, do not assign a custom view to it; the navigation item ignores
custom views in the back bar button anyway.
The default value of this property is nil.
Unfortunately I didn't find any way of disabling back button with saving its native look and behaviour, because any time when I try to set custom UIBarButtonItem into navigationItem.backBarButtonItem property - it gets updated with appropriate native back button style and it always has enabled == YES.
I think this is done by Apple for a reason because we basically shouldn't force the user to stay on a detail screen and disable him from going back.
Also, in iOS7 and later user always can use swipe-from-left-edge gesture (if you don't disable it) to go back.
The only one ugly thing that I can recommend is to create a custom UIBarButtonItem and set it into leftBarButtonItem with 'Back' title, target and selector which will pop your viewController. By default it will substitute native back button.
Then you can disable it as usual using navigationItem.leftBarButtonItem.enabled = NO.
Unfortunately it will not look and act (in case of title updating depending on available space) as native back button :(
Just set a disabled back button on the navigation item of the previous view controller. Don't try to disable your custom back button if you already had one, won't work. Just set a new one which is disabled. You can reach the previous navigation item through the UINavigationBar.backItem property.
// set disabled back button
let backButton = UIBarButtonItem(title: "Back", style: UIBarButtonItem.Style.plain, target: nil, action: nil)
backButton.isEnabled = false
navigationController?.navigationBar.backItem?.backBarButtonItem = backButton
// disable pop gesture
navigationController?.interactivePopGestureRecognizer?.isEnabled = false

How can an iOS7-style "Now Playing" button be added to an UINavigationBar?

I'd like to add an iOS7 Music app style "Now Playing" button to the UINavigationBar
The button should have:
two lines of text
a right pointing chevron
How can this be achieved?
You will probably need the image for the chevron. If that's okay for you then you can create a UIButton with proper title and image insets and pass to initWithCustomView: method.
Note: you will also need to set numberOfLines = 2 for this button which as far as I know you can not do in IB

Add border and shadow to the buttons

I want to add medium thick black border and shadow to the buttons that I have added in my iPad application. I have taken those buttons as custom as I have applied images on them. How can I add border and shadow to ht
To add shadows and border is simple.
1) Add the QuartzCore framework to your target.
2) Import the framework header in the class where you want to add borders and shadows. (Or if you have custom class for the button then you can simple import this framework in that class.)
3) To add the border to the button use this code (where button is an IBOutlet connected with the button in interface):
[self.button.layer setBorderWidth:3.0];
[self.button.layer setBorderColor:[[UIColor blackColor] CGColor]];
4) To add the shadow to the button use the following code:
[self.button.layer setShadowOffset:CGSizeMake(5, 5)];
[self.button.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.button.layer setShadowOpacity:0.5];
You can play around with the values and see how it will affect the behaviour.
If you were in Cocoa, you could use NSView's setShadow. (NSView is an ancestor of NSButton.) I don't see the equivalent method for UIView, so I don't think there is any simple way of doing that in iOS. Come to think of it, I don't think I've seen that effect in iOS apps, period.
But since you're using custom button images anyway, why not prepare images that include shadow and border?