I want to set up a constrain in storyboard but deactivate it in Storyboard
for a while, until a user interaction happens. Is it possible?
Try setting constraint.active to NO, then set it back to YES to re-enable it.
If you want to disable it in the storyboard, go to the Identity inspector(), then click the + button under the User Defined Runtime Attributes header. Double-click the section of the highlighted row that says “keyPath”. Type in active, then uncheck the checkbox.
Yes it is possible.
Create an IBOutlet for that NSLayoutConstraint and connect it your mentioned contraint in Storyboard.
#property (nonatomic, strong) IBOutlet UIView *myView;
#property (nonatomic, strong) IBOutlet NSLayoutConstraint *myConstraint;
myConstraint is a constraint on myView
On viewDidLoad write this code: [_myView removeConstraint:_myConstraint];
Then, when a user interaction happens: [_myView addConstraint:_myConstraint];
Related
Is there a way to set the backgroundColor of the bar that contains the inputAssistantItem elements? (the bar that contains the "next" button in the image):
Also, is it possible to add a UILabel (like a title) to the bar?
I suggest you use inputAccessoryView as it is a UIView you can just do pretty much everything you want with it.
I opened the "UITextInput.h" file and there seems to be no way to achieve what you want as the object does not give you the tools.
This is the code I found
NS_CLASS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED __WATCHOS_PROHIBITED #interface UITextInputAssistantItem : NSObject
/// Default is YES, controls if the user is allowed to hide the shortcuts bar. Does not influence the built in auto-hiding logic.
#property (nonatomic, readwrite, assign) BOOL allowsHidingShortcuts;
/// Contains UIBarButtonItemGroups that should be displayed in the leading position on the keyboard's assistant bar.
#property (nonatomic, readwrite, copy) NSArray<UIBarButtonItemGroup *> *leadingBarButtonGroups;
/// Contains UIBarButtonItemGroups that should be displayed in the trailing position on the keyboard's assistant bar.
#property (nonatomic, readwrite, copy) NSArray<UIBarButtonItemGroup *> *trailingBarButtonGroups;
#end
BAD POSSIBLE SOLUTION could be checking the superview of the buttons you create until you find the toolbar and then trying to change what you want. I honestly recommend you NOT TO DO THIS.
Can somebody tell me why none of the buttons under the "License Agreement View" UIView object in my .xib file are triggering an action? It seems that the Scrollview object is messing up the behavior. When the buttons are directly under the "Scroll View" object (as opposed to the "License Agreement View" UIView object), then they function properly. But, I need to group my buttons under the UIViews as shown in the view hierarchy below.
Here's the view layout:
Here's my view hierarchy:
Here's the corresponding .m file:
#interface MYViewController ()
- (IBAction)licenseAgreementPressed:(id)sender;
- (IBAction)legalDisclaimerPressed:(id)sender;
- (IBAction)privacyStatementPressed:(id)sender;
#property (strong, nonatomic) IBOutlet UIView *licenseAgreementView;
#property (weak, nonatomic) IBOutlet UIButton *legalDisclaimerButton;
#property (strong, nonatomic) IBOutlet UIButton *privacyStatementButton;
#end
#implementation MYViewController
- (IBAction)licenseAgreementPressed:(id)sender
{
NSLog(#"Pressed A");
}
- (IBAction)legalDisclaimerPressed:(id)sender
{
NSLog(#"Pressed B");
}
- (IBAction)privacyStatementPressed:(id)sender
{
NSLog(#"Pressed C");
}
#end
Make sure you have made connection between IBAction(code) and UIButton(in xib) , please check this post How do I name and link an IBAction button created in a storyboard
Did you connect your actions to the elements in interface builder by control-dragging it?
If your actions are connected you will see a little filled out circle on the left of the line in your editor.
Check this tutorial for further information on how to connect your storyboard elements to your code.
It is because none of the buttons are inside the bounds of the license agreement view. A button outside its superview's bounds is untappable.
So the problem was the links, buttons, and text fields were not actually located within the bounds specified the parent views because the original .xib file didn't have the required constraints pinned to those elements. I discovered this by checking the "clip to bounds" checkbox in the Attributes Inspector pane. Whenever "clip to bounds" was checked, the app was NOT displaying any of the above view objects; I could only see links, buttons, and text fields when "clip to bounds" was unchecked but unfortunately, those elements were not clickable at that point. After setting the necessary constraints, however, the view elements were correctly placed within the bounds of their parent views and the text fields, labels, and buttons became clickable. I'm attaching the constraints that I used to fix the problem. Note: the constraints that are not expanded only include a height constraint.
Can I make my UIView #property inspectable?
#interface Superview : UIView
#property (nonatomic, weak, readonly) IBInspectable UIButton *stopButton;
#property (nonatomic, weak, readonly) IBInspectable PKCircleProgressView *circleProgressView;
#end
I've created a designable view PKCircleProgressView, and I want it to be editable from the IB. Also I've created another designable view which contains PKCircleProgressView as subview, and I want it to be editable too.
Is there any way to edit circleProgressView's properties if I use Superview in the IB?
I've come out only with one idea, to create a common protocol for both views, and implement methods such as:
- (void)setProgress:(CGFloat)progress {
self.circleProgressView.progress = progress;
}
but it is not easy to do it with every property, especially if I want to create another View that contains my Superview.
IBInspectable does not support UIView or it's subtypes. It supports simple values.
If your custom progress view is IBDesignable why not set it's properties like radius and foreground color to be IBInspectable and in interface builder select the progress view and change the progress view's properties?
If your creating an IBDesignable superview you might be able to expose the inspectable properties of it's button and progress view using something like the Decorator pattern.
Apple's Documentation
No you cannot make UIView Inspectable. The usage of IBInspectable is only for configuring "key value" coded property of an instance in a NIB or storyboard.
Suppose, if UIView will be the key then what will be its value? There won't be value for UIView, so you cannot make UIView Inspectable.
But we can make UIView's attributes Inspectable such as:
UIView's backgroundColor, width, height, etc
Sample project: IBDesignable and IBInspectable
i'm trying to create an ui button with image and text.
What i need is simple:
an image centered on the first row and on another row a label centered.
So i've created an uibutton in my storyboard, set text and background in this way:
But the result isn't good for me.
This is what i have:
and this is what i need:
Can someone help me?
thanks!
EDIT
I've created a custom UIButton in this way:
.h
#import <UIKit/UIKit.h>
#interface MenuButton : UIButton
#property (weak, nonatomic) IBOutlet UIImageView *image;
#property (weak, nonatomic) IBOutlet UILabel *text;
#end
.m
#import "MenuButton.h"
#implementation MenuButton
#end
And in interface builder i create a view with class MenuButton addedd an image and a label and connecting to .h.
Now my question is:
How can i pass to that new button the image and the label in order to instantiate multiple "custom button" with different value inside?
Thanks!
You just create a UIButton subclass.
1)
If you are using IB: then you can create 2 properties in the .h
#property (weak, nonatomic) IBOutlet UIImageView *image;
#property (weak, nonatomic) IBOutlet UILabel *text
next you need to connect all the properties to the objects in the IB
If you are using code the remove the IBOutlet and move the properties to the .m
2)
Now all you need to do is manage the behaviour of the properties.
in IB, just add the autolayout constraints to the subclass and change their constant property value - check this tutorial
in code, you can do this by setting their frame with animation to make them larger/smaller
EDIT
Ok, after reading your update you need to change the subclass from UIButton to UIView.
This way you can add a UIView in your storyboard and add the UImageView & UILable. After doing so you can change the UIView's class to your subclass.
Then, click on the UIView and open the connections inspector. You will see the IBOutlets you have declared in th UIView subclass, you can just drag from the connections inspector to the UIImageView & UILabel to crete the connections
I just dragged a UIImageview onto a storyboard in xcode 5. I am coming from .NET where this would add an object of type UIImageView to the main form. Is this the way to think about it in IOS? Where do I click in the xcode IDE to get the name of the instance of UIImageView?
You dragged a UIImageView into a storyboard. You need to see which view controller this UIImageView object lives in and then you can connect that UIImageView to an IBOutlet, which is how your view controller (the implementation or code for which you're working on, which also happens to be a subclass of UIViewController) will interact with the UIImageView object.
You have to write a IBOutlet in the corresponding ViewController.h file like this.
#property (nonatomic , strong) IBOutlet UIImageView *myImageView ;
Then in your ViewController.m , use #synthesize after #implementation tag.
Then go back to the Interface Builder and connect the IBOutlet myImageView to your ImageView which you have dragged there. Hope it helps.