ios UIButton subclass to reuse button in Storyboard - ios6

I have created an app which uses the storyboard feature in Xcode.
I need to put a button on a few views which is a "Call us" button. The button will have the same look, text and action associated with it.
It's that reason which I thought would be best to create a subclass of the button and set all the button properties from there.
There are no coding problems, but when I drag on a button to a view on the storyboard, change it's class to the "CallButton" subclass name - it simply ignores all the formatting.
Am I missing something? Is there an easier way to reuse a button? Normally (old school way) I would simply call the button from the code, but as I've used the storyboard, I need to drag and drop the button really.
Thanks for any advice!

Xcode wont reflect the changes you make programatically in your subclass, but if you're setting up the buttons look in your subclass it should look as expected when you run the application.
Ideally you would setup your CustomButton in its initWithFrame and initWithCoder methods.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html

Related

Toggle Button - Beveled Effect

I've been trying to create a toggle button with a "simple" bevel effect for my WPF Window. At first I've tried to apply the BevelBitmapEffect but apparently it is not deprecated and there are no visual changes when applied.
I've have tried many other "tweaks" with no success.
The kind of button I'm going for is something like this:
Edit: I was able to create this effect by having two pictures (unpressed and pressed). Still, if anyone knows how to do this without any external resources that would be great.
You have two options for this,
Create a Style for the ToggleButton that gives the desired look, this page has an example of a simple style for a toggle button.
Make a toggle button custom control, which is the same idea but can be a bit simpler if you need to use the same style in multiple places or applications.

Move focus on WPF

I have one application in WPF.
In which we have some button control. On the click of the button it opnes a popup control.
The problems is after clicking on button it does not move focus on opened pop up.
I want the solution using XAMLcode only.there is no CS file.
Thanks
Harshil
To do this in XAML only you will need classes which let you invoke methods since that is necessary to move the focus around, Interactivity from the Blend SDK lets you do this to some degree but i did not get it to work with the Focus method. Possibly something like this markup programming library would work; you could also implement some custom markup extension which does the invocation, but in general XAML-only is not trivial here.
...and it is somewhat pointless to do that in the first place. If you have imperative code like "open popup then focus it" then just use code behind, that's what it is for.

Re-using Buttons in WPF

I have a bunch of different objects that are commonly edited in the same TabControl using different DataTemplates, but I want each DataTemplate to have a common look and feel with Ok and Cancel buttons at the bottom right of each tab that will close the tab or save the content and then close the currently selected tab. What's the best way to place buttons on each tab ? Is there a way to do it without copying and pasting the buttons and stack panel across all of my data templates ?
Sure, you can create your own OkCancelSaveControl. In WPF, creating a "user control" is much easier than it sounds. Here is a tutorial. In a nutshell, you
create a new user control,
create properties in the user control that give the your control the information it needs to perform its duties (e.g. the tab that it's supposed to close or the data object that it's supposed to save),
if necessary, create events that the user control raises (OkClick), in case some tab requires special treatment.
I would make a custom control, lets call it MyCoolTabItem, that inherits from the TabItem class, and just throw your buttons into the control. Then just add a MyCoolTabItem instead of a TabItem to all of your TabControls and it will have all of your buttons on it.
You could make a base view class that held those buttons. Views that needed the buttons would inherit them and common functionality.

Silverlight: Creating a modal control

I have a window with some contents. I'd like to click a button and another control (a grid/border) slides up. But i'd like the contents of the window that is under this slided up control to be modal. I cannot click or use keyboard to activate anything.
Thank you.
For a modal window I would use the ChildWindow class. Microsoft provides the templates used for all of their major controls and objects so one can take what they did and change it. The ChildWindow template and styles page has a pretty good explanation of the layout so one can figure out what to change. You should just be able to instantiate a new ChildWindow, set its template to your custom template, and rock out!
Sounds to me you could do with using the ChildWindow control instead, which handles most of this for you. Make a copy of its template and tweak it up to get your slide-in effect.
You can create a control filling the complete canvas and make it transparent.

Best way to modify Button behavior and Content, but maintain styles?

I'm trying to create a control in Silverlight that inherits from Button so that I can perform a specific action everytime it is clicked. I'm doing this because I'd like to reuse this custom button in several locations with the same functionality.
I'd like to create the control in such a way so that I have a can set the custom Button's Content to a specific default icon image, but still have the rest of the button's style coming from either the default button style, or being automatically set by the toolkit Themes.
I'd also like to have the Content be described and editable in XAML rather than code if possible.
It seems like this would be a pretty common problem for Silverlight developers - is there a good way to tackle it?
If you use a normal button and edit an "Empty Template", then you can style the button to have any content you wish and expose properties that you can set in the XAML for Icons etc.
By using the standard button control, you will have all the behaviors that you require.
I believe this is what you're looking for, if not can you expand on your question.
--EDIT--
Ok, I get what you are trying to do now. So what you might want to consider is creating a custom button class that inherits from Button. Then you can override the OnClick method to handle your logic. When it comes to the XAML, you can create a template style for a TargetType of your custom button class, that would be styled to your requirements.
HTH, if you need some examples place a comment and I'll mock up some examples

Resources