when I press on it I can change position freely in View
-(IBAction) add :(id)sender {
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
UITextField * textfieldToAdd = [[[UITextField alloc] initWithFrame:frame] autorelease];
textfieldToAdd.borderStyle = UITextBorderStyleRoundedRect;
textfieldToAdd.textColor = [UIColor blackColor];
textfieldToAdd.font = [UIFont systemFontOfSize:17.0];
textfieldToAdd.placeholder = #"";
textfieldToAdd.backgroundColor = [UIColor whiteColor];
textfieldToAdd.autocorrectionType = UITextAutocorrectionTypeNo ; // no auto correction support
textfieldToAdd.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
textfieldToAdd.returnKeyType = UIReturnKeyDone;
textfieldToAdd.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textfieldToAdd.tag = kViewTag; // tag this control so we can remove it later for recycled cells
textfieldToAdd.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
// Add an accessibility label that describes what the text field is for.
[textfieldToAdd setAccessibilityLabel:NSLocalizedString(#"textfieldToAdd", #"")];
[self.view addSubview:textfieldToAdd];
}
First add the gestureRecognizer to your ViewDidLoad and then create the function
or better look here MoveME example
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(panPiece:)];
[panGesture setMaximumNumberOfTouches:2];
[panGesture setDelegate:self];
[self addGestureRecognizer:panGesture];
- (void)panPiece:(UIPanGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGPoint translation = [gestureRecognizer translationInView:self.view];
textfieldToAdd.center = CGPointMake([self center].x + translation.x, [self center].y + translation.y);
[gestureRecognizer setTranslation:CGPointZero inView:[self superview]];
}
}
i want dragging this textField
(void)viewDidLoad {
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(add:)] autorelease];
}
-(IBAction) add :(id)sender {
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
UITextField * textfieldToAdd = [[[UITextField alloc] initWithFrame:frame] autorelease];
textfieldToAdd.borderStyle = UITextBorderStyleRoundedRect;
textfieldToAdd.textColor = [UIColor blackColor];
textfieldToAdd.font = [UIFont systemFontOfSize:17.0];
textfieldToAdd.placeholder = #"";
textfieldToAdd.backgroundColor = [UIColor whiteColor];
textfieldToAdd.autocorrectionType = UITextAutocorrectionTypeNo ; // no auto correction support
textfieldToAdd.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
textfieldToAdd.returnKeyType = UIReturnKeyDone;
textfieldToAdd.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textfieldToAdd.tag = kViewTag; // tag this control so we can remove it later for recycled cells
textfieldToAdd.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
// Add an accessibility label that describes what the text field is for.
[textfieldToAdd setAccessibilityLabel:NSLocalizedString(#"textfieldToAdd", #"")];
[self.view addSubview:textfieldToAdd];
}
Related
Adding UIImageView on UIScrollView and adding UIPanGestureRecognizer to it
UIImageView* lbl = [[UIImageView alloc]init];
NSString* tempStr = [NSString stringWithFormat:#"images/%#",[self.cloudArray objectAtIndex:i]];
NSString* imgPath = [self appendDocumentDirectoryPath:tempStr];
lbl.image = [[[UIImage alloc] initWithContentsOfFile:imgPath] autorelease];
[lbl setUserInteractionEnabled:YES];
//add gestures
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(moveImage:)];
[panGesture setMinimumNumberOfTouches:1];
[panGesture setMaximumNumberOfTouches:1];
[lbl addGestureRecognizer:panGesture];
[panGesture release];
CGSize expectedLabelSize = CGSizeMake(150, height);
lbl.frame = CGRectMake(pntX, pntY, expectedLabelSize.width, height);
[rectFrame addObject:[NSValue valueWithCGRect:lbl.frame]];
lbl.tag = i;
[cloudScrollView addSubview:lbl];
[lbl release];
lbl = nil;
pntX = pntX + space + expectedLabelSize.width;
[cloudScrollView setContentSize:CGSizeMake([cloudArray count]*170, 160)];
#pragma mark METHOD TO CATCH MOVE GESTURE EVENTS
- (void)moveImage:(UIPanGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateChanged) {
location1 = [gesture locationInView:cloudScrollView];
view1 = [gesture view];
if (isFirstTime) {
isFirstTime = NO;
draggedTag = view1.tag;
}
[view1 setCenter:CGPointMake(location1.x, location1.y)];
}
if (gesture.state == UIGestureRecognizerStateEnded) {
CGPoint pnt = [gesture locationInView:customTableView];
NSIndexPath* indexPath = [customTableView indexPathForRowAtPoint:pnt];
NSLog(#"indexpath = %d",indexPath.row);
if (index >= 0) {
[self.ansArray replaceObjectAtIndex:indexPath.row withObject:[self.cloudArray objectAtIndex:draggedTag]];//[self.cloudArray objectAtIndex:draggedTag]
[customTableView reloadData];
}
CGRect draggedItemRect = [[rectFrame objectAtIndex:draggedTag] CGRectValue];
view1.frame = draggedItemRect;
isFirstTime = YES;
}
}
I am dynamically creating UILabels and then saving their tag in an NSMutableArray. I then have a method that detects taps (clicks) on these UILabels. Basically when a UILabel that has been dynamically generated is clicked I want to have it deleted without deleting other labels. However, in future I may want to do more then just delete. But at the moment I feel like I am stuck at a dead end trying to find a way to do this. Any ideas?
Heres my code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// set corner radius
coverview.hidden=YES;
labeltextfield.hidden=YES;
textcreate.hidden=YES;
labeltags = [NSMutableArray array];
labeltext = [NSMutableArray array];
}
-(IBAction)removeboard
{
[labeltextfield resignFirstResponder];
}
-(void)showtextcreator {
// Create bg cover
coverview.hidden=NO;
labeltextfield.hidden=NO;
textcreate.hidden=NO;
//Make sure creating screen is always on top
[self.view bringSubviewToFront:coverview];
[self.view bringSubviewToFront:labeltextfield];
[self.view bringSubviewToFront:textcreate];
}
-(void)createtext {
NSInteger obj = [labeltags count] +1 ;
[labeltags addObject:[NSNumber numberWithInteger:0]];
int posx = arc4random() % 300 ;
int posy = arc4random() % 400 ;
int frame = arc4random() % 400 ;
NSString *txt = labeltextfield.text;
// NSString *framename = (#"frame%i",frame);
[labeltext addObject:txt];
[labeltags addObject:[NSNumber numberWithInteger:0]];
CGRect labelframe = CGRectMake( posx, posy, 100, 30);
label = [[UILabel alloc] initWithFrame: labelframe];
[label setText: [NSString stringWithFormat:#"%#", txt]];
[label setTextColor: [UIColor orangeColor]];
label.backgroundColor = [UIColor clearColor];
label.tag=obj;
[self.view addSubview: label];
label.userInteractionEnabled = YES;
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:#selector(labelDragged:)];
[label addGestureRecognizer:gesture];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapAction)];
[label addGestureRecognizer:recognizer];
coverview.hidden=YES;
labeltextfield.hidden=YES;
textcreate.hidden=YES;
}
- (void)labelDragged:(UIPanGestureRecognizer *)gesture
{
label = (UILabel *)gesture.view;
CGPoint translation = [gesture translationInView:label];
// move label
label.center = CGPointMake(label.center.x + translation.x,
label.center.y + translation.y);
// reset translation
[gesture setTranslation:CGPointZero inView:label];
}
- (void)tapAction {
UILabel *labelnew = (UILabel *)[self.view viewWithTag:1];
NSLog(#"Text is %#",labelnew.text);
}
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapAction:)];
[label addGestureRecognizer:recognizer];
- (void)tapAction:(UITapGestureRecognizer *)tapGesture {
UILabel *labelTapped = (UILabel *)tapGesture.view;
//delete it using removeFromSuperView or do whatever you need with tapped label
}
Details:
1.Modify your -(void)createtext method.
2: Add a parameter to the target for UITapGestureRecognizer
3.Receive the sender gesture in - (void)tapAction:
4.Get the tapped UILabel.
Thats it.
I am creating two label programmatically using this code..
-(void)addLabel:(id)sender
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.count = theDataObject.count+1;
NSLog(#"count is :%i",theDataObject.count);
if (theDataObject.count == 2) {
addLabel.enabled = NO;
}
if (theDataObject.count == 1) {
CGRect imageFrame = CGRectMake(10, 10, 150, 80);
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
blabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 100, 100)];
blabel.text = #"Write here";
//alabel.text = self.newsAsset.title;
blabel.adjustsFontSizeToFitWidth = NO;
blabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
blabel.font = [UIFont boldSystemFontOfSize:18.0];
blabel.textColor = [UIColor blueColor];
// alabel.shadowColor = [UIColor whiteColor];
// alabel.shadowOffset = CGSizeMake(0, 1);
blabel.backgroundColor = [UIColor clearColor];
blabel.lineBreakMode = UILineBreakModeWordWrap;
blabel.numberOfLines = 10;
blabel.minimumFontSize = 8.;
blabel.adjustsFontSizeToFitWidth = YES;
[blabel sizeToFit];
labelResizableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// enable touch delivery
blabel.userInteractionEnabled = YES;
//tao gasture recognizer for label
UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(blabelTap:)];
doubleTap.numberOfTapsRequired = 2;
[blabel addGestureRecognizer:doubleTap];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(longPress:)];
[longPressGesture setMinimumPressDuration:1];
[blabel addGestureRecognizer:longPressGesture];
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [greetString sizeWithFont:blabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:blabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = blabel.frame;
newFrame.size.height = expectedLabelSize.height+40;
newFrame.size.width = expectedLabelSize.width+40;
blabel.frame = newFrame;
labelResizableView.frame = newFrame;
labelResizableView.contentView = blabel;
labelResizableView.delegate = self;
labelResizableView.tag =2;
[self.view addSubview:labelResizableView];
}else if (theDataObject.count == 2) {
CGRect imageFrame = CGRectMake(10, 10, 150, 80);
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
clabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 100, 100)];
clabel.text = #"Write here";
//alabel.text = self.newsAsset.title;
clabel.adjustsFontSizeToFitWidth = NO;
clabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
clabel.font = [UIFont boldSystemFontOfSize:18.0];
clabel.textColor = [UIColor blueColor];
// alabel.shadowColor = [UIColor whiteColor];
// alabel.shadowOffset = CGSizeMake(0, 1);
clabel.backgroundColor = [UIColor clearColor];
clabel.lineBreakMode = UILineBreakModeWordWrap;
clabel.numberOfLines = 10;
clabel.minimumFontSize = 8.;
clabel.adjustsFontSizeToFitWidth = YES;
[clabel sizeToFit];
labelResizableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// enable touch delivery
clabel.userInteractionEnabled = YES;
//tao gasture recognizer for label
UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(clabelTap:)];
doubleTap.numberOfTapsRequired = 2;
[clabel addGestureRecognizer:doubleTap];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(longPress:)];
[longPressGesture setMinimumPressDuration:1];
[clabel addGestureRecognizer:longPressGesture];
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [greetString sizeWithFont:clabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:clabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = blabel.frame;
newFrame.size.height = expectedLabelSize.height+40;
newFrame.size.width = expectedLabelSize.width+40;
clabel.frame = newFrame;
labelResizableView.frame = newFrame;
labelResizableView.contentView = clabel;
labelResizableView.delegate = self;
labelResizableView.tag=3;
[self.view addSubview:labelResizableView];
}
}
And when user long press button than it will be deleted...
- (void)longPress:(UILongPressGestureRecognizer *)longPressGesture {
if (longPressGesture.state == UIGestureRecognizerStateEnded) {
//NSLog(#"Long press Ended");
// NSLog(#"blabel long pressed");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Delete Label" message:#"Want delete label" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes",nil];
[alert show];
}
else {
//NSLog(#"Long press detected.");
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Yes"])
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
if (theDataObject.count!=0) {
theDataObject.count = theDataObject.count-1;
}
addLabel.enabled = YES;
[labelResizableView removeFromSuperview];
// NSLog(#"yes btn tapped");
}
}
but now when i longpree blabel than still clabel is deleted and it will never delete blabel.thanx in advance.
Use the Tag property to remove the labelResizableView.
-(void)addLabel:(id)sender
{
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
labelResizableView.tag = 100;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Yes"])
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
if (theDataObject.count!=0) {
theDataObject.count = theDataObject.count-1;
}
addLabel.enabled = YES;
UILabel *tempLabel = (UILabel *)[self.view viewWithTag:100];
if(tempLabel)
[tempLabel removeFromSuperview];
}
}
hope this code help you :)
NSArray *subArray = [self.view subviews];
if([subArray count] != 0) {
for(int i = 0 ; i < [subArray count] ; i++) {
[[subArray objectAtIndex:i] removeFromSuperview];
}
}
To add control in your view:
[self.view addsubview:yourcontrolid];
ex:
[self.view addsubview:labelid];
To add control from your view:
[controlid removefromsuperview];
ex
[labelid removefromsuperview];
you are adding with :
[self.view addSubview:labelResizableView];
than remove it the labelResizableView, and release the clabel or blabel, whatever is in your case.
Maybe this gives an example
It is because your code
else if (theDataObject.count == 2) {
is calling and in this code you are adding
labelResizableView.contentView = clabel;
and then you are adding this to you view
[self.view addSubview:labelResizableView];
So when you are deleting labelResizableView
[labelResizableView removeFromSuperview];
So the result is you are adding labelResizableView 2 times and remove the labelResizableView which have clabel.
I made a UIView subclass (bowl) and when I try to make a bowl within a bowl and then center the inner one on the outer one's center it end up getting placed below and to the right of the center. How would I properly center it?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//CGColorRef lightGrayColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0].CGColor;
self.userInteractionEnabled = YES;
UIGestureRecognizer *twoFingerZ = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(pinchZoom:)] ;
[self addGestureRecognizer:twoFingerZ];
UILabel *label = [[UILabel alloc] init];
[label setFont:[UIFont fontWithName:#"Arial" size:64]];
label.text = [NSString stringWithFormat:#"March"];
[label sizeToFit];
label.center = self.center;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor lightGrayColor];
self.backgroundColor = [UIColor whiteColor];
[self addSubview:label];
}
return self;
}
-(void)pinchZoom:(UIPinchGestureRecognizer *)recognizer
{
if([(UIPinchGestureRecognizer*)recognizer state] == UIGestureRecognizerStateEnded) {
CGAffineTransform newForm = CGAffineTransformMakeScale(600/self.bounds.size.width, 600/self.bounds.size.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self setTransform:newForm];
return;
[UIView commitAnimations];
}
if([(UIPinchGestureRecognizer*)recognizer state] == UIGestureRecognizerStateBegan) {
subClip = [[clipView alloc] initWithFrame:CGRectMake((self.center.x - ([delegate getSize:self].width/2)), (self.center.y - ([delegate getSize:self].height/2)), [delegate getSize:self].width, [delegate getSize:self].height)];
subClip.transform = CGAffineTransformMakeScale(0.1, 0.1);
[self addSubview:subClip];
bowl *newB = [[bowl alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
newB.center = self.center;
// right here! *************
[self addSubview:newB];
}
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
}
EDIT: I fixed it. Apparently the center value for a UIView isn't exactly what I thought it was (it looks like it's the position of the center in another view or something), so instead of newB.center = self.center, the right way to do it was newB.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
To center the inner label you should be able to use:
label.center=CGPointMake(self.center.x,self.center.y);
But first you'll probably want to define the frame size of the inner label:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,yourWidth,yourHeight);
You may also want to center the text within the inner label:
label.textAlignment = UITextAlignmentCenter;
Also, not sure what you're intending in your code with this:
[label sizeToFit];
But according to the documentation, sizeToFit will resize and moves the receiver view so it encloses its subviews. In this case, it doesn't appear that your inner view has subviews. So your centering may be off because you may have unexpected dimensions for your inner label. Try setting the background color for that label to something you can see (i.e. not [UIColor clearColor]) to double check its dimensions. May help solve the centering problem.
Good luck.
i would like to know configuration about UITextField standard please
- (IBAction)add:(id)sender
{
UITextField * textfieldToAdd = [[[UITextField alloc] init] autorelease];
// ... configuration code for textfield ...
[self.view addSubview:textfieldToAdd];
}
Here is a code from Apple's example UICatalog
#pragma mark -
#pragma mark Text Fields
- (UITextField *)textFieldNormal
{
if (textFieldNormal == nil)
{
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
textFieldNormal = [[UITextField alloc] initWithFrame:frame];
textFieldNormal.borderStyle = UITextBorderStyleBezel;
textFieldNormal.textColor = [UIColor blackColor];
textFieldNormal.font = [UIFont systemFontOfSize:17.0];
textFieldNormal.placeholder = #"<enter text>";
textFieldNormal.backgroundColor = [UIColor whiteColor];
textFieldNormal.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textFieldNormal.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
textFieldNormal.returnKeyType = UIReturnKeyDone;
textFieldNormal.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textFieldNormal.tag = kViewTag; // tag this control so we can remove it later for recycled cells
textFieldNormal.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
// Add an accessibility label that describes what the text field is for.
[textFieldNormal setAccessibilityLabel:NSLocalizedString(#"NormalTextField", #"")];
}
return textFieldNormal;
}
- (UITextField *)textFieldRounded
{
if (textFieldRounded == nil)
{
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
textFieldRounded = [[UITextField alloc] initWithFrame:frame];
textFieldRounded.borderStyle = UITextBorderStyleRoundedRect;
textFieldRounded.textColor = [UIColor blackColor];
textFieldRounded.font = [UIFont systemFontOfSize:17.0];
textFieldRounded.placeholder = #"<enter text>";
textFieldRounded.backgroundColor = [UIColor whiteColor];
textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textFieldRounded.keyboardType = UIKeyboardTypeDefault;
textFieldRounded.returnKeyType = UIReturnKeyDone;
textFieldRounded.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textFieldRounded.tag = kViewTag; // tag this control so we can remove it later for recycled cells
textFieldRounded.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
// Add an accessibility label that describes what the text field is for.
[textFieldRounded setAccessibilityLabel:NSLocalizedString(#"RoundedTextField", #"")];
}
return textFieldRounded;
}
- (UITextField *)textFieldSecure
{
if (textFieldSecure == nil)
{
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
textFieldSecure = [[UITextField alloc] initWithFrame:frame];
textFieldSecure.borderStyle = UITextBorderStyleBezel;
textFieldSecure.textColor = [UIColor blackColor];
textFieldSecure.font = [UIFont systemFontOfSize:17.0];
textFieldSecure.placeholder = #"<enter password>";
textFieldSecure.backgroundColor = [UIColor whiteColor];
textFieldSecure.keyboardType = UIKeyboardTypeDefault;
textFieldSecure.returnKeyType = UIReturnKeyDone;
textFieldSecure.secureTextEntry = YES; // make the text entry secure (bullets)
textFieldSecure.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textFieldSecure.tag = kViewTag; // tag this control so we can remove it later for recycled cells
textFieldSecure.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
// Add an accessibility label that describes what the text field is for.
[textFieldSecure setAccessibilityLabel:NSLocalizedString(#"SecureTextField", #"")];
}
return textFieldSecure;
}
- (UITextField *)textFieldLeftView
{
if (textFieldLeftView == nil)
{
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
textFieldLeftView = [[UITextField alloc] initWithFrame:frame];
textFieldLeftView.borderStyle = UITextBorderStyleBezel;
textFieldLeftView.textColor = [UIColor blackColor];
textFieldLeftView.font = [UIFont systemFontOfSize:17.0];
textFieldLeftView.placeholder = #"<enter text>";
textFieldLeftView.backgroundColor = [UIColor whiteColor];
textFieldLeftView.keyboardType = UIKeyboardTypeDefault;
textFieldLeftView.returnKeyType = UIReturnKeyDone;
textFieldLeftView.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textFieldLeftView.tag = kViewTag; // tag this control so we can remove it later for recycled cells
// Add an accessibility label that describes the text field.
[textFieldLeftView setAccessibilityLabel:NSLocalizedString(#"CheckMarkIcon", #"")];
textFieldLeftView.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"segment_check.png"]];
textFieldLeftView.leftViewMode = UITextFieldViewModeAlways;
textFieldLeftView.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
}
return textFieldLeftView;
}
Go through the reference doc for UITextField Class also try to read UITextFieldDelegate. Look for the different tasks that can be performed and see the methods, properties available for it. And use it according to your requirement.