change button type programmatically - cocoa-touch

Is it possible to change programmatically the type of button in Xcode?
I am trying to change the type from "Info Light" to "Info Dark".

No, you can't. These button types are subclasses of UIButton, not settable properties. You can specify a type when creating a button in Interface Builder or when creating the button with the class method [UIButton buttonWithType:(UIButtonType)buttonType].
If you want to change the button type, I would suggest creating a button of each type with the same frame, one with the hiddenproperty set to TRUE. Toggle between them as needed by setting the hidden property. They can share the same target and action.
The question is a near-duplicate of this one:
Change UIButton type programatically

Related

Buttons as Outlets vs IBActions [Objective C + Xcode]

What is the point of ever setting a button as an outlet? I am following a tutorial and the teacher didn't really mention why he set a button as an outlet. A button is suppose to do an action/call a method and so we set it as an IBAction.
He sets the button as an outlet and then proceeds to change the text of the button through Xcode in viewDidLoad, but why not just keep it as an IBAction and change the text by using setTitle: forState:UIControlStateNormal ?
Isn't a button suppose to cause an action by definition?
in some logic cases you would need to change the behaviour of the button , e.g. upon invoking an action (triggered by other event )you will need to disable it or change its backgroundColor or text.
you don't have to set at all times , but in many cases it is really useful

How to disable context menus with right mouse click in an NSTextField (Cocoa)?

I'm working on a Cocoa application that has editable text fields. These text fields need to accept values but don't need to be spell checked or use any of the other options given in the default context menu. I've read that the easiest way to remove the right click/ opt + click context menu is to override the function:
rightMouseDown:(NSEvent *)
I've done this in a custom NSTextfield class. This fix blocks the user from right clicking when the text box is enabled and unselected, but as soon as the user double clicks/enters the text field for editing the default right click functionality returns.
Is this because the firstResponder switches to a class in the inheritance chain upon trying to edit the field? Is this approach the right way to disable all context menu functionality for this NSTextField?
Thanks!
When a text field is editing, the actual first responder is the "field editor", an NSTextView supplied by the window. The field editor always uses the control on whose behalf it is acting as its delegate.
So, in order to influence its behavior with respect to the contextual menu, you need to use a custom subclass of NSTextField. (I guess you already are to override -rightMouseDown:.) Then, implement the text view delegate method -textView:menu:forEvent:atIndex: and return nil (i.e. no menu).

NSColorWell not sending action on click?

Inside my .xib, I've placed an NSColorWell inside an NSView, and connected an IBAction in the controller to the NSColorWell's Sent Actions (via File's Owner). I figured I would respond to a click in my controller and send activate to bring up the NSColorPanel.
But unlike other my controls, I'm not getting the IBAction called. Clicking invokes a drag action on the color. I noticed this control doesn't derive from NSActionCell (like all my other controls). What's the proper control that is supposed to be used to both display a color and invoke the NSColorWell when clicked?
(note: this is Xcode/IB 3.2.x)
You listed both osx and ios in the tags, but I'm guessing this is an OS X problem.
There is a "Bordered" checkbox in IB's Attributes Inspector for NSColorWell. This toggles between a button-style color well, which is what you're asking for, and a color well which you can only drag a color swatch from. Make sure that's checked and you'll get the action like you're expecting.

Enable text box when checkbox is ON using objective c

How do I enable a text box when I check the checkbox through bindings in Cocoa?
Bind the checkbox's value and the text field's enabled to the same property of the same object—usually either your File's Owner (typically a window controller, view controller, or document) or some kind of object controller (such as an array controller).
First you connect your text box to an IBOutlet.
And instead of using binding, you can set your button to fire an action method when it is touched (this is called an IBAction and there's a bit more detail in this related question)
When the state of the button (or in your case, checkbox) changes, the IBAction method gets called and based on the state of the checkbox, you can enable or disable your textbox via the outlet you connected.

use UIMenuController with text

So i would like to use the UIMenuController to display text. i would like to add in help buttons (press a little button and something will pop up describing what something does) that would display either a UIMenuController or something that looks similar to it. it would just display a few lines of text and dismiss when pressed.
it kinda looks like UIMenuController is only meant for button selection. i could just use one button and set the title to the message i wish to display, but am doubtful on how well that would work. are there any other options available?
A UIMenuController takes it content from its menuItems property and the documentation says :
The default value is nil (no custom menu items). Each menu item is an
instance of the UIMenuItem class. You may create your own menu items,
each with its own title and action selector, and add them to the
editing menu through this property. Custom items appear in the menu
after any system menu items.
So you are obliged to use UIMenuItem objects as content for your UIMenuController. UIMenuItem only inherits from NSObject, and stores only a title and an action, both required. This make you unable to use any other kind of data as UIMenuItem.
As it is not an UIView, you can give it a UIButton or a UIImageView.
You could think to override UIMenuController but again it is a direct child of NSObject, so it doesn't have any behavior for customization.
The only solution left to you, is to rewrite your own UIMenuController, deriving it from UIToolbar for example. This would give you more or less the same look, you just have to customize the arrow and the round corner.