Image in UITextField only showing in first text box, not second - iphone

need to add a downward facing arrow to a text box. decided to use the rightViewMode to display it. it works for the first textfield i use, but does not show up in the second. it happens in 3 different views where i need to do this.
code:
//added to post
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)];
UIView *rightPaddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
UIImageView *unitArrowImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"prev-arrow.png"]];
unitArrowImage.frame = CGRectMake(0, 0, 20, 20);
[unitArrowImage setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[rightPaddingView addSubview:unitArrowImage];
//other code
UITextField *seedRateUnitTextField = [[UITextField alloc] initWithFrame:myRect];
seedRateUnitTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
seedRateUnitTextField.placeholder = #"Unit";
seedRateUnitTextField.borderStyle = UITextBorderStyleLine;
seedRateUnitTextField.backgroundColor = [UIColor whiteColor];
seedRateUnitTextField.textColor = [UIColor textFieldTextColor];
seedRateUnitTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
seedRateUnitTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
seedRateUnitTextField.layer.borderWidth = 1.0f;
seedRateUnitTextField.leftView = paddingView;
seedRateUnitTextField.leftViewMode = UITextFieldViewModeAlways;
seedRateUnitTextField.rightView = rightPaddingView;
seedRateUnitTextField.rightViewMode = UITextFieldViewModeAlways;
seedRateUnitTextField.delegate = self;
seedRateUnitTextField.tag = 0;
[myScrollView addSubview:seedRateUnitTextField];
[self.dataSetDictionary setValue:seedRateUnitTextField forKey:#"seedRateUnitData"];
myRect = CGRectMake(200, ((4 * 40) + 140), 170, 30);
UITextField *plantingDepthTextField = [[UITextField alloc] initWithFrame:myRect];
plantingDepthTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
plantingDepthTextField.placeholder = #"Enter Planting Depth";
plantingDepthTextField.borderStyle = UITextBorderStyleLine;
plantingDepthTextField.backgroundColor = [UIColor whiteColor];
plantingDepthTextField.textColor = [UIColor textFieldTextColor];
plantingDepthTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
plantingDepthTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
plantingDepthTextField.layer.borderWidth = 1.0f;
plantingDepthTextField.leftView = paddingView;
plantingDepthTextField.leftViewMode = UITextFieldViewModeAlways;
plantingDepthTextField.delegate = self;
plantingDepthTextField.tag = 0;
[myScrollView addSubview:plantingDepthTextField];
[self.dataSetDictionary setValue:plantingDepthTextField forKey:#"plantingDepthData"];
myRect = CGRectMake(375, ((4 * 40) + 140), 85, 30);
UITextField *plantingDepthUnitTextField = [[UITextField alloc] initWithFrame:myRect];
plantingDepthUnitTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
plantingDepthUnitTextField.placeholder = #"Unit";
plantingDepthUnitTextField.borderStyle = UITextBorderStyleLine;
plantingDepthUnitTextField.backgroundColor = [UIColor whiteColor];
plantingDepthUnitTextField.textColor = [UIColor textFieldTextColor];
plantingDepthUnitTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
plantingDepthUnitTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
plantingDepthUnitTextField.layer.borderWidth = 1.0f;
plantingDepthUnitTextField.leftView = paddingView;
plantingDepthUnitTextField.leftViewMode = UITextFieldViewModeAlways;
plantingDepthUnitTextField.rightView = rightPaddingView;
plantingDepthUnitTextField.rightViewMode = UITextFieldViewModeAlways;
plantingDepthUnitTextField.delegate = self;
plantingDepthUnitTextField.tag = 0;
[myScrollView addSubview:plantingDepthUnitTextField];
[self.dataSetDictionary setValue:plantingDepthUnitTextField forKey:#"plantingDepthUnitData"];
result:
this method works great to add padding to the left side. its almost like the rightPaddingView gets used up in the first text box.... /boggle

You cant add the same UIImageView to two textfields, a UIView can only be in one view at a time, so you should make various instances of your imageview, as many as you want textfields and assign it like that..

Related

About IOS UIScrollView Sliding automatic will bounce back

My app's UIScrollView Sliding automatic will bounce back,what can i do?
I do not want!
my code below:
- (void)initScrollView {
// a page is the width of the scroll view
sv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 96, 320, 300)];
sv.contentSize = CGSizeMake(sv.frame.size.width * 3, sv.frame.size.height* 2);
sv.pagingEnabled = YES;
sv.clipsToBounds = YES;
sv.showsHorizontalScrollIndicator = NO;
sv.showsVerticalScrollIndicator = YES;
sv.scrollsToTop = NO;
sv.directionalLockEnabled = YES;
sv.delegate = self;
[self.view addSubview:sv];
currentPage = 0;
pageControl.numberOfPages = 3;
pageControl.currentPage = 0;
pageControl.backgroundColor = [UIColor clearColor];
[self createAllEmptyPagesForScrollView];
}
- (void)createAllEmptyPagesForScrollView {
tapView1 = [[UIView alloc]init];
tapView1.backgroundColor = [UIColor clearColor];
tapView1.frame = CGRectMake(320*0, 0, 320, sv.frame.size.height);
tapView2 = [[UIView alloc]init];
tapView2.backgroundColor = [UIColor clearColor];
tapView2.frame = CGRectMake(320*1, 0, 320, sv.frame.size.height);
tapView3 = [[UIView alloc]init];
tapView3.backgroundColor = [UIColor clearColor];
tapView3.frame = CGRectMake(320*2, 0, 320, sv.frame.size.height);
[sv addSubview:tapView1];
[sv addSubview:tapView2];
[sv addSubview:tapView3];
}
i konw why I slide up automatically bounce back,my code have problem!Not bove code!thanks everyone!

How to load content into a WebView by touching a UIView

I Have a collection of views in a view controller. by touching one of those views I would like to load specific data, for ex. a webpage into a web view that is on the same view controller
How would you accomplish that?
Thank you in advance
Here is my code with does not want to work:
UIView *categoryTitle = [[UIView alloc] initWithFrame:CGRectMake(0, 166 * counter
, 500, 20)];
UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 20)];
[categoryLabel setBackgroundColor:[UIColor clearColor]];
NSMutableArray *allCurrentNews = [[News alloc] allNewsFromCategory:cat.CategoryId];
categoryLabel.text = cat.Name;
categoryLabel.textColor = [UIColor whiteColor];
[categoryTitle addSubview:categoryLabel];
UIColor *myblack = [[UIColor alloc] initWithRed:0.14 green:0.14 blue:0.14 alpha:1];
UIColor *ligheterBlac = [[UIColor alloc] initWithRed:0.227 green:0.22 blue:0.22 alpha:1];
[categoryTitle setBackgroundColor:myblack];
UIScrollView *tempScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 166 * counter, 500, 166)];
UIColor *tempcolor = ligheterBlac;
tempScroll.layer.borderColor = [UIColor colorWithRed:0.34 green:0.34 blue:0.34 alpha:1].CGColor;
tempScroll.layer.borderWidth = 0.5f;
int countnews = 0;
for (News *news in allCurrentNews)
{
UIView *newsContainer = [[UIView alloc] initWithFrame:CGRectMake(160 * countnews, 30, 156, 126)];
newsContainer.tag = countnews + 1;
[newsContainer addGestureRecognizer:recognizer];
//newsContainer.NewsId = news.NewsId;
LazyImageView *image = [[LazyImageView alloc] initWithURl:[NSURL URLWithString:news.Thumbnail]];
image.frame = CGRectMake(0, 0 , 156, 96);
UILabel *newsTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 96, 156, 30)];
newsTitle.backgroundColor = myblack;
newsTitle.numberOfLines = 2;
newsTitle.font = [UIFont systemFontOfSize:11];
newsTitle.text = news.Title;
newsTitle.textColor = [UIColor whiteColor];
newsTitle.textAlignment = UITextAlignmentCenter;
newsContainer.layer.borderColor = [UIColor colorWithRed:0.34 green:0.34 blue:0.34 alpha:1].CGColor;
newsContainer.layer.borderWidth = 0.5f;
[newsContainer addSubview:image];
[newsContainer addSubview:newsTitle];
countnews ++;
[tempScroll setContentSize:CGSizeMake(allCurrentNews.count * 156, 96)];
[tempScroll addSubview:newsContainer];
//[image release];
}
[tempScroll setBackgroundColor: tempcolor];
[categories addSubview:tempScroll];
[categories addSubview:categoryTitle];
[tempcolor release];
[tempScroll release];
counter ++;
}
self.detailsView.layer.masksToBounds = NO;
self.detailsView.layer.shadowOffset = CGSizeMake(-10, 5);
self.detailsView.layer.shadowRadius = 5;
self.detailsView.layer.shadowOpacity = 0.3;
[self.view addSubview:categories];
[self.view addSubview:_detailsView];
[self.view addSubview:MainSubTitle];
[self.view addSubview:MainTitle];
Use the UITapGestureRecognizer.
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:selector(processTap:)];
UIView *targetView = //assign the view you need
targetView.tag = 5;
[targetView addGestureRecognizer:recognizer];
}
- (void)processTap:(UITapGestureRecognizer *)recognizer {
UIView *view = recognizer.view;
if (view.tag == 5) {
}
}

ContainerView hide UILabel

I want to use UILabel in ContainerView.
So I am using this code for that.
UILabel *myLabel = [[[UILabel alloc] initWithFrame:CGRectMake(16, 60, 300, 150)] autorelease];
myLabel.numberOfLines = 0;
myLabel.font = [UIFont systemFontOfSize:13.5];
myLabel.text = [theQuiz objectAtIndex:row+3] ;
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.backgroundColor = [UIColor clearColor];
myLabel.layer.cornerRadius = 8.0;
[myLabel sizeToFit];
[self.view addSubview:myLabel];
//ContainerView
UIView *ChallengeView = [[UIView alloc] initWithFrame:CGRectMake(8, 55, 300, 10 + Challenge.frame.size.height)];
ChallengeView.layer.borderColor = [[UIColor purpleColor ] CGColor];
[ChallengeView setBackgroundColor:[UIColor whiteColor]];
ChallengeView.layer.cornerRadius = 8 ;
ChallengeView.layer.borderWidth = 1.5;
[self.view addSubview:ChallengeView];
[ChallengeView release];
Now problem is that when i set background color for ContainerView it hides the text of myLabel
Any Solution ??
What is happening is that you containerView is being added above label either you add label after containerView or do this:
[self.view bringSubviewToFront:myLabel];
You add the ChallengeView first , Then add the myLabel.
Otherwise u can do as like #xs2bush said,
[self.view bringSubviewToFront:myLabel];
Bcz the ChallengeView hides the label.

cocoa-touch: Why is font not applied?

I'm trying to code the appearance of an UILabel, but I can't get another font applied. The funny (or rather annoying) thing is that if I add a second UILabel, the font WILL BE APPLIED for the second label, BUT NOT the first. I'm slightly going crazy on this... especially the font size won't change if I try to.
My code (found in my ViewDidLoad):
NSString* dateWeekDay = #"MON";
CGRect dateWeekDayFrame = CGRectMake(183, 12, 34, 21);
viewNoteDateWeekDay = [[UILabel alloc] initWithFrame:dateWeekDayFrame];
viewNoteDateWeekDay.text = dateWeekDay;
viewNoteDateWeekDay.textColor = [UIColor blackColor];
viewNoteTitle.font = [UIFont fontWithName:#"Helvetica Neue" size:70.0f]; // I know this size is crazy, but it's just to show that it has no effect whatsoever...
viewNoteDateWeekDay.transform = CGAffineTransformMakeRotation( ( -90 * M_PI ) / 180 );
viewNoteDateWeekDay.backgroundColor = [UIColor clearColor];
NSString* dateDay = #"01";
CGRect dateDayFrame = CGRectMake(209, 3, 47, 50);
viewNoteDateDay = [[UILabel alloc] initWithFrame:dateDayFrame];
viewNoteDateDay.text = dateDay;
viewNoteDateDay.textColor = [UIColor blackColor];
viewNoteDateDay.font = [UIFont fontWithName:#"Helvetica Neue" size:33.0f];
viewNoteDateDay.backgroundColor = [UIColor clearColor];
NSString* dateMonth = #"SEPTEMBER";
CGRect dateMonthFrame = CGRectMake(249, 6, 93, 31);
viewNoteDateMonth = [[UILabel alloc] initWithFrame:dateMonthFrame];
viewNoteDateMonth.text = dateMonth;
viewNoteDateMonth.textColor = [UIColor blackColor];
viewNoteDateMonth.font = [UIFont fontWithName:#"Helvetica Neue" size:12.0f];
viewNoteDateMonth.backgroundColor = [UIColor clearColor];
You are specifying the wrong variable name when you're setting the font property. Your code says: viewNoteTitle.font = ... when it should read viewNoteDateWeekDay.font = ...

Posting Tweets from Iphone App

My app has three text fields:
1) Username
// Initialization code
usernameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 5, 280, 30)];//usernameTextField released
usernameTextField.placeholder = #"Username";
usernameTextField.textAlignment = UITextAlignmentLeft;
//Username text field
usernameTextField.backgroundColor = [UIColor clearColor];
usernameTextField.borderStyle = UITextBorderStyleRoundedRect;
usernameTextField.autocorrectionType = UITextAutocorrectionTypeNo;
usernameTextField.keyboardType = UIKeyboardTypeURL;
usernameTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
2) Password
// Initialization code
passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 90, 280, 30)];
passwordTextField.placeholder = #"Password";
passwordTextField.textAlignment = UITextAlignmentLeft;
//Password text field
passwordTextField.backgroundColor = [UIColor clearColor];
passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
passwordTextField.autocorrectionType = UITextAutocorrectionTypeNo;
passwordTextField.keyboardType = UIKeyboardTypeURL;
passwordTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
passwordTextField.secureTextEntry = YES;
3) Text View
textView = [[UITextView alloc] initWithFrame:CGRectMake(5, 10, 310, 180)];
textView.layer.cornerRadius = 8;
textView.clipsToBounds = YES;
textView.font = [UIFont fontWithName:#"Arial" size:16.0f];
What is the best/quick way to use these to upload tweets to twitter directly, with the login details for the first two and the Tweet being the textView?
You should look into using MGTwitterEngine. It provides everything you need
Authenticating is as easy as
MGTwitterEngine *twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:#"username" password:#"password"];
and then you just use
- (NSString *)sendUpdate:(NSString *)status;
to post an update