Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-12-2010, 12:15 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 50
Default Add button to right of UITextField

I have been scouring the net to try and implement a plus (+) button in a UITextField. I know I need to set the rightView to a view containing this button but all the examples I have seen create a custom UIImageView which then gets set. I could go this way but found this code;

[UIButton buttonWithType:UIButtonTypeContactAdd];

but can't see how you assign it as UITextField rightView expects a type of UIView. If I have to go the rightView = [[UImageView alloc] initWithImage... I will but thought this way would be more straightforward and I'm to keen to understand it more.

Can anyone give me some pointers?


Cheers

Gary
garyk1968 is offline   Reply With Quote
Old 03-13-2010, 02:17 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 13
Default

Quote:
Originally Posted by garyk1968 View Post
I have been scouring the net to try and implement a plus (+) button in a UITextField. I know I need to set the rightView to a view containing this button but all the examples I have seen create a custom UIImageView which then gets set. I could go this way but found this code;

[UIButton buttonWithType:UIButtonTypeContactAdd];

but can't see how you assign it as UITextField rightView expects a type of UIView. If I have to go the rightView = [[UImageView alloc] initWithImage... I will but thought this way would be more straightforward and I'm to keen to understand it more.

Can anyone give me some pointers?


Cheers

Gary
I'm stumped on the same issue tonight. I need to toggle between Refresh and Cancel buttons and don't know how to set a target and action on a UIView versus a system button. I also don't want to have to hack my own icon images to mimic the system ones.

Why can't we just make a system button and add it as the view?
Scenario is offline   Reply With Quote
Old 03-13-2010, 06:48 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default

You could try adding the button as a subview to the UITextField.
harrytheshark is offline   Reply With Quote
Old 03-13-2010, 11:02 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 13
Default

Well the trick is to use a UIButton with an image:

Code:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
	[button setImage:[UIImage imageNamed:@"RefreshIcon.png"] forState:UIControlStateNormal];
	[button setImage:[UIImage imageNamed:@"RefreshIcon.png"] forState:UIControlStateHighlighted];
	button.imageEdgeInsets = UIEdgeInsetsMake(0, -16, 0, 0);
	[button addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventTouchUpInside];
	addressBar.rightView = button;
	addressBar.rightViewMode = UITextFieldViewModeAlways;
Scenario is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 256
16 members and 240 guests
@sandris, ADY, dacapo, Dani77, djohnson, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, timle8n1, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0