Mail app up/down arrows - iphone

Is there a way to get access to the up/down arrows used in the Mail app and implement them the same way?

No, there's no supported way to do it. I'd suggest you file a bug on Radar asking Apple to include more built-in artwork. In the mean time, you'll just have to draw your own.

Can you clarify your question?
The graphics for up/down are not easily accessible, though you can probably find a way to get them. For instance, see http://0xced.blogspot.com/2009/04/extract-uikit-artwork.html.
But if you're looking for the behavior, it's really quite simple. The arrows are on a momentary UISegmentedControl. Attach to valueChanged: to tell when the user taps on one of them, and use selectedSegmentIndex to tell which one they tapped.

Nowadays they are part of the sample code of IOS 4.1. Check the NavBar sample.

As Steven Fisher said, you can’t access the Apple graphic easily. But they are relatively easy to remake.
Given the images I had some trouble making this look right in iOS 7 where a UISegmentedControl will not work. This code did the trick however (added to viewDidLoad in the ViewController).
UIButton *upButton = [UIButton buttonWithType:UIButtonTypeCustom];
[upButton setImage:[upImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
forState:UIControlStateNormal];
upButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 6);
[upButton sizeToFit];
UIButton *downButton = [UIButton buttonWithType:UIButtonTypeCustom];
[downButton setImage:[downImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
forState:UIControlStateNormal];
downButton.contentEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
[downButton sizeToFit];
UIBarButtonItem *upButtonItem = [[UIBarButtonItem alloc] initWithCustomView:upButton];
UIBarButtonItem *downButtonItem = [[UIBarButtonItem alloc] initWithCustomView:downButton];
[upButton addTarget:self action:#selector(YOUR_UP_SELECTOR:) forControlEvents:UIControlEventTouchUpInside];
[downButton addTarget:self action:#selector(YOUR_DOWN_SELECTOR:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItems = #[downButtonItem, upButtonItem];

Related

UIButton with custom Type seems not to work properly

something strange happened during the development of my app. I have a view with several UIButtons in it. All are using custom artwork and are UIButton with CostumType.
For me everything felt right. In the simulator and on the phone.
But when I give the app in someone else's hand the person taps on a button and it won't work. It feels like the button is just reaction to a certain tap which in fact doesn't feel right (if you compare it to normal behavior).
What can I do to make it behave normal? Normal means that somebody who is used to iOS Apps can use it like he except it works.
Here is an example code for a button:
focusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[focusButton setFrame:CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor)+108, self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2))+2, 36, 40)];
focusButton.contentHorizontalAlignment = false; // I think these lines doesn't effect the behavior
focusButton.contentVerticalAlignment = false;
[focusButton setBackgroundImage:[UIImage imageNamed:#"arrowUp.png"] forState:UIControlStateNormal];
[focusButton setBackgroundImage:[UIImage imageNamed:#"arrowUpH.png"] forState:UIControlStateHighlighted];
[focusButton addTarget:self action:#selector(focusOrDefocusCourse) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:focusButton];
The Button Background looks like this:
this is woking fine.. Once just test with the frame..
UIButton *btn_foucs = [UIButton buttonWithType:UIButtonTypeCustom];
[btn_foucs setFrame:CGRectMake(20, 20, 200, 40)];
[btn_foucs setImage:[UIImage imageNamed:#"btn_erase.png"] forState:UIControlStateNormal];
[btn_foucs setImage:[UIImage imageNamed:#"btn_erase_h.png"] forState:UIControlStateHighlighted];
[self.view addSubview:btn_foucs];
You may like to take a look at the UIButton property imageEdgeInsets. This allows you to make the image draw into only part of the frame, so that the touchable area is bigger than the image itself (reducing the chance of 'missing' the button). You could do the following, for example:
int touch_offset = 10;
[focusButton setFrame:CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor)+108-touch_offset, self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2))+2-touch_offset, 36+(touch_offset*2), 40+(touch_offset*2))];
focusButton.imageEdgeInsets = UIEdgeInsetsMake(touch_offset, touch_offset, touch_offset, touch_offset);
This should make the touchable area 10 pixels wider than the image on each side, adjustable by changing the touch_offset value. As a general guideline, Apple recommend using touchable areas no smaller than 44x44 pixels.

In iOS, can a UIButton be added by alloc and initWithFrame?

A button can be added by:
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(100, 100, 160, 50);
[myButton setTitle:#"click me" forState:UIControlStateNormal];
[self.view addSubview:myButton];
but can we go with the initWithFrame method:
UIButton *myButton2 = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 160, 50)];
//myButton2.buttonType = UIButtonTypeRoundedRect;
myButton2.titleLabel.text = #"click me";
[self.view addSubview:myButton2];
but line 2 above is commented out because it causes an error for a "read only" property, and with that line commented out, still no button shows up at all... can a UIButton be added if using initWithFrame to begin with?
(update: I set a yellow background to see the view's area, and found that the label text of button 2 actually shows up as "click me" in white... but touching it has no visual effect... so I wonder how to change code sample 2 to make it work...)
Yes of course it can. I got into a little bit of a discussion as to that readonly buttonType property a while back. The general concensus is that there is neither a safe way, nor a good reason, for anyone to switch the type of a button. And besides, +buttonWithType returns an instance of UIButton just as well as +Alloc and -init do, so it isn't a problem.

iPhone UI small button?

http://g.virbcdn.com/_f/cdn_images/resize_1280x640/29/PageImage-489404-2437983-IMG_4531.PNG
Hi all, we are trying to figure out how to do the small orange numbered label on the left in the image above. As you can see, when the number is 6, it looks like a circle. When it is 33, the label looks wider. Does anyone know how to make it? Our developer believes it is made with UIButton. Is it possible to do it with label? Thanks in advance.
cornerRadius property of the CALayer class can be use to achieve this. Every view has a CALayer instance on which we can perform certain action. Means we can get rounded corners by using -
myLabel.layer.cornerRadius = //radius that we want;
Also for accessing layer we need to have following framework in our application-
<QuartzCore/QuartzCore.h>
First Add QuartzCore FrameWork, then
use in .m file
#import "QuartzCore/CALayer.h"
then use this code where do you want to show
UIButton *Mybutton = [UIButton buttonWithType:UIButtonTypeCustom];
Mybutton.backgroundColor=[UIColor orangeColor];
[Mybutton addTarget:self action:#selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[Mybutton setTitle:#"1" forState:UIControlStateNormal];
Mybutton.frame = CGRectMake(135.0, 180.0, 40.0, 40.0);
Mybutton.clipsToBounds = YES;
Mybutton.layer.cornerRadius = 20;
Mybutton.layer.borderColor=[UIColor greenColor].CGColor;
Mybutton.layer.borderWidth=2.0f;
[self.view addSubview:Mybutton];
button will look like...

Custom UIAlertView iphone

I have a problem .. I used this http://kwigbo.com/post/318396305/iphone-sdk-custom-uialertview-background-color to create my own custom UIAlertView.
I do not know why but this will not work:
UILabel *theTitle = [theAlert valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [theAlert valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];
the color of the title does not change .. the color of texbody it's ok.
How can I customize the buttons?
Hi Achieved same thing using custom UIAleartView.
Make a custom view as follows.
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 5.0f, 262.0, 49)];
tempView.backgroundColor = [UIColor clearColor];
UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 262.0, 49)];
lblTitle.font = [UIFont fontWithName:#"Arial" size:22.0f];
lblTitle.textColor = [UIColor whiteColor];
lblTitle.textAlignment = UITextAlignmentCenter;
lblTitle.text = #"Subscribe";
lblTitle.backgroundColor = [UIColor clearColor];
[tempView addSubview:lblTitle];
alreadySubscriber = [[UIButton alloc] initWithFrame:CGRectMake(12, 260, 262.0, 50)];
alreadySubscriber.layer.cornerRadius = 25.0f;
[alreadySubscriber setTitle:#"Already a subscriber" forState:UIControlStateNormal];
[alreadySubscriber setBackgroundImage:[UIImage imageNamed:#"BTN0.png"] forState:UIControlStateNormal];
[alreadySubscriber setBackgroundImage:[UIImage imageNamed:#"BTN1.png"] forState:UIControlStateSelected];
[tempView addSubview:alreadySubscriber];
Insert this in UIAleartView
[self insertSubview:tempView atIndex:0];
[self setNeedsLayout];
Override layoutsubview as you have already done push all other controls down equal to view Height.
-> basically matter is to hide UIAleartView's title behind a label.
Not sure exactly what your issue might be, but we faced a similar situation when trying to workout a custom UIAlertView, so might be similar.
The custom solution in the link you provided appears to manipulate the alerts title and background by accessing the subview hierarchy and 'guessing' which subview might be which. (I may be wrong, didn't look through it in detail) The problem with this approach is that it'll work fine for one OS version, but in subsequent OS versions, Apple may restructure this subview hierarchy in some manner, and this 'guesswork' is no longer accurate. (i.e. the subview assumed to be the background image may not be).
This could be the case, seeing that posted link is an year old. If you're proceeding with this, you may have to review the subview hierarchy to see if they still match up.
I believe, that you can find proper solution without using standart tools, which are present in UIAlertView. But in this case, you application will be not approve for AppStore. That way, I strongly recommend you, avoid to using custom buttons in AlertView.
Maybe, you will find solution using UIActionSheet instead UIAlertView . It's more customizing.
If #"_titleLabel" is part of the UIAlertView hierarchy (which looks likely given the _ prefix), I can't recommend your approach.
Apple might some day change the key strings: If #"_titleLabel" ever changes, say to #"_titleLabelView", you're sunk and you might never know that you're sunk. This might even be grounds for rejection, I wouldn't know.
It's better to start out from scratch with your own custom view, subclassing UIView. Only then can you guarantee that this will be stable from OS to OS. On top of this, the time you lose trying to find a shortcut will be positively spent constructing some thing durable.

navigation Controller button left

In my application, i have some leftBarbutton of the navigation bar set to " retour" and some others set to "back" i would like to set all my buttons to "retour", how to do this please ? i have spend many hours to dos this.
thanks
I reckon you want to change the language, rather than the button description itsself.
In oder to change the language have a look into the (appname)-Info.plist.
There is an Attribute: Localization native development region.
Change it accordingly to, i guess in your case France if. am not horribl wrong.
Cheers,
Sebastian
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:#"retour" forState:UIControlStateNormal];
btn.frame=CGRectMake(3, 2, 53, 30);
UIBarButtonItem *btnBack=[[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem=btnBack;
[btnBack release];
[btn release];