Posting Tweets from Iphone App - iphone

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

Related

Make UINavigationBar title be user editable

How do I make UINavigationBar title to be user editable, I've tried setting the titleView to be a textfield however it doesn't look the same.. It's missing that outline or drop shadow. I'm aiming for it to look like the default one.
This is what i'm implementing at the moment:
_titleField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 200, 26)];
[_titleField setDelegate:self];
_titleField.text = _bugDoc.data.title;
_titleField.font = [UIFont boldSystemFontOfSize:20];
_titleField.textColor = [UIColor whiteColor];
_titleField.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = _titleField;
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadTitle];
}
- (void)loadTitle
{
txtField_navTitle = [[UITextField alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x,7,self.view.bounds.size.width,31)];
txtField_navTitle.delegate = self;
[txtField_navTitle setBackgroundColor:[UIColor clearColor]];
txtField_navTitle.textColor = [UIColor whiteColor];
txtField_navTitle.textAlignment = UITextAlignmentCenter;
txtField_navTitle.borderStyle = UITextBorderStyleNone;
txtField_navTitle.font = [UIFont boldSystemFontOfSize:20];
txtField_navTitle.autocorrectionType = UITextAutocorrectionTypeNo;
txtField_navTitle.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.navigationItem setTitleView:txtField_navTitle];
txtField_navTitle.layer.masksToBounds = NO;
txtField_navTitle.layer.shadowColor = [UIColor whiteColor].CGColor;
txtField_navTitle.layer.shadowOpacity = 0;
[txtField_navTitle release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
self.title = textField.text;
return YES;
}
Please dont forget to #import <QuartzCore/QuartzCore.h>
Try this way this works for me.
// Custom Navigation Title.
UILabel* tlabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 300, 40)];
tlabel.text=self.title;
tlabel.textAlignment=NSTextAlignmentCenter;
tlabel.font = [UIFont boldSystemFontOfSize:17.0];
tlabel.textColor=[UIColor colorWithRed:7.0/255.0 green:26.0/255.0 blue:66.0/255.0 alpha:1.0];
tlabel.backgroundColor =[UIColor clearColor];
tlabel.adjustsFontSizeToFitWidth=YES;
self.navigationItem.titleView=tlabel;

How I can add multiple textField in a single Loop?

I wants add multiple UITextFields in a single loop. And identify them when user interact with UITextFields . So please help me.
Thanks
Currently I place UITextField Individually, like this
txt_FirstName=[[UITextField alloc]initWithFrame:CGRectMake(framex1, framey1, framex2, framey2)];
txt_FirstName.borderStyle = UITextBorderStyleRoundedRect;
txt_FirstName.font = [UIFont systemFontOfSize:15];
txt_FirstName.placeholder = #"First Name";
txt_FirstName.autocorrectionType = UITextAutocorrectionTypeNo;
txt_FirstName.keyboardType = UIKeyboardTypeDefault;
txt_FirstName.returnKeyType = UIReturnKeyDone;
txt_FirstName.clearButtonMode = UITextFieldViewModeWhileEditing;
txt_FirstName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txt_FirstName.delegate = self;
[frameView addSubview:txt_FirstName];
[txt_FirstName release];
framey1=framey1+50;
txt_MiddleName=[[UITextField alloc]initWithFrame:CGRectMake(framex1, framey1, framex2, framey2)];
txt_MiddleName.borderStyle = UITextBorderStyleRoundedRect;
txt_MiddleName.font = [UIFont systemFontOfSize:15];
txt_MiddleName.placeholder = #"Middle Name";
txt_MiddleName.autocorrectionType = UITextAutocorrectionTypeNo;
txt_MiddleName.keyboardType = UIKeyboardTypeDefault;
txt_MiddleName.returnKeyType = UIReturnKeyDone;
txt_MiddleName.clearButtonMode = UITextFieldViewModeWhileEditing;
txt_MiddleName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txt_MiddleName.delegate = self;
[frameView addSubview:txt_MiddleName];
[txt_MiddleName release];
Please use this, but Implement UITextField delegate in your .h file. but You should have to change your place holder according to your requirement like 1 for FirstName, 2 for MiddleName etc.
First create common function like this,
-(void)setTextfieldStyle:(UITextField *)pTmpTextField
{
pTmpTextField.borderStyle = UITextBorderStyleRoundedRect;
pTmpTextField.font = [UIFont systemFontOfSize:15];
pTmpTextField.placeholder = #"First Name";
pTmpTextField.autocorrectionType = UITextAutocorrectionTypeNo;
pTmpTextField.keyboardType = UIKeyboardTypeDefault;
pTmpTextField.returnKeyType = UIReturnKeyDone;
pTmpTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
pTmpTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
pTmpTextField.delegate = self;
}
and use this for creating UITextFiled,
int y = 0;
for(int i=0;i < 5;i++)
{
UITextField *txtTemp=[[UITextField alloc]initWithFrame:CGRectMake(0, y, 300, 31)];
txtTemp.tag = i;
[self setTextfieldStyle:txtTemp];
[self.view addSubview:txtTemp];
[txtTemp release];
y+=36;
}
This is UITextField's delegate method,
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(#"%#",textField.text);
}
Hope this works for you..
If you want to set attributes of a bunch of text fields in a loop, you could also do something like:
NSMutableArray* allTextFields = [NSMutableArray array];
// create the textFields here, I'm assuming you need to keep individual
// references to them.
txt_FirstName=[[UITextField alloc]init];
pTmpTextField.placeholder = #"First Name";
[allTextFields addObject:txt_FirstName];
// now add the common style stuff and frame
[allTextFields enumerateObjectsUsingBlock:^(UITextField* textField, NSUInteger idx, BOOL* stop) {
textField.frame = CGRectMake(framex1, framey1 + ( 50 * idx), framex2, framey2);
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = #"First Name";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
}];

SizeToFit Navigation Bar Item (UITextField)

How do I size a UITextField to fit the whole UINavigationBar? So far I have this:
locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];
locationField.delegate = self;
locationField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
locationField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
locationField.textAlignment = UITextAlignmentLeft;
locationField.borderStyle = UITextBorderStyleRoundedRect;
locationField.font = [UIFont fontWithName:#"Helvetica" size:15];
locationField.autocorrectionType = UITextAutocorrectionTypeNo;
locationField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
I basically want to turn locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)]; to fit the UINavigationBar, probably using sizeToFit, just not 100% sure how to implement it.
Thanks.
You can try the
[self.navigationItem setTitleView:locationField];
See code below:
UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];
locationField.delegate = self;
locationField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
locationField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
locationField.textAlignment = UITextAlignmentLeft;
locationField.borderStyle = UITextBorderStyleRoundedRect;
locationField.font = [UIFont fontWithName:#"Helvetica" size:15];
locationField.autocorrectionType = UITextAutocorrectionTypeNo;
locationField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.navigationItem setTitleView:locationField];
[locationField release];
Nevermind, got it fixed by switching the CGRect from:
UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];
to
UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,300,31)];

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

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..

How to create a passcode view iphone

I'd like to add a passcode lock in my app...
I created the view but I don't know how to get it working...
This is what I'd like it must do:
- If an user is setting his passcode, he must type it twice and the code must verify if the passcode typed the second time is the same of the first time.
- If the passcode controller is called by a setting view, for example, to set the passcode, it must have a cancel button on the navigation bar but if it is called at app launch, the cancel button mustn't be enabled.
summaryLabel is the label that show a message like "Passcode didn't match. Try again." when the passcode is not the same as the one written previously or saved.
EDIT1: How can I use textField:shouldChangeCharactersInRange:replacementString method to do this?
This is the code:#import "PasscodeController.h"
#implementation PasscodeController
#synthesize panelView;
#synthesize summaryLabel;
#synthesize titleLabel;
#synthesize textField1;
#synthesize textField2;
#synthesize textField3;
#synthesize textField4;
#synthesize hiddenTF;
-(void)viewDidLoad {
self.title = #"Passcode";
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 22, 270, 30)];
titleLabel.font = [UIFont boldSystemFontOfSize:15];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.textColor = [UIColor colorWithRed:66.0/255.0 green:85.0/255.0 blue:102.0/255.0 alpha:1.0];
titleLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:titleLabel];
[titleLabel release];
summaryLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 130, 270, 40)];
summaryLabel.font = [UIFont boldSystemFontOfSize:12];
summaryLabel.numberOfLines = 0;
summaryLabel.baselineAdjustment = UIBaselineAdjustmentNone;
summaryLabel.textAlignment = UITextAlignmentCenter;
summaryLabel.textColor = [UIColor colorWithRed:66.0/255.0 green:85.0/255.0 blue:102.0/255.0 alpha:1.0];
summaryLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:summaryLabel];
[summaryLabel release];
textField1 = [[UITextField alloc] initWithFrame:CGRectMake(25, 60, 60, 60)];
textField1.borderStyle = UITextBorderStyleBezel;
textField1.textColor = [UIColor blackColor];
textField1.textAlignment = UITextAlignmentCenter;
textField1.font = [UIFont systemFontOfSize:41];
textField1.secureTextEntry = YES;
textField1.backgroundColor = [UIColor whiteColor];
textField1.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField1];
[textField1 release];
textField2 = [[UITextField alloc] initWithFrame:CGRectMake(95, 60, 60, 60)];
textField2.borderStyle = UITextBorderStyleBezel;
textField2.textColor = [UIColor blackColor];
textField2.textAlignment = UITextAlignmentCenter;
textField2.font = [UIFont systemFontOfSize:41];
textField2.secureTextEntry = YES;
textField2.backgroundColor = [UIColor whiteColor];
textField2.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField2];
[textField2 release];
textField3 = [[UITextField alloc] initWithFrame:CGRectMake(165, 60, 60, 60)];
textField3.borderStyle = UITextBorderStyleBezel;
textField3.textColor = [UIColor blackColor];
textField3.textAlignment = UITextAlignmentCenter;
textField3.font = [UIFont systemFontOfSize:41];
textField3.secureTextEntry = YES;
textField3.backgroundColor = [UIColor whiteColor];
textField3.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField3];
[textField3 release];
textField4 = [[UITextField alloc] initWithFrame:CGRectMake(235, 60, 60, 60)];
textField4.borderStyle = UITextBorderStyleBezel;
textField4.textColor = [UIColor blackColor];
textField4.textAlignment = UITextAlignmentCenter;
textField4.font = [UIFont systemFontOfSize:41];
textField4.secureTextEntry = YES;
textField4.backgroundColor = [UIColor whiteColor];
textField4.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField4];
[textField4 release];
hiddenTF = [[UITextField alloc] initWithFrame:CGRectZero];
hiddenTF.hidden = YES;
hiddenTF.delegate = self;
hiddenTF.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:hiddenTF];
[hiddenTF release];
[hiddenTF becomeFirstResponder];
}
Thanks a lot!
Another solution, KVPasscodeViewController (mine), is available here: https://github.com/Koolistov/Passcode (BSD license).
If this can be helpful for other, I solved my problem with this source code on GitHub: PTPasscodeViewController.
I changed it a little bit to adapt it to my needs and now works greatly :)
If you want to use it, there are all the information about how to use it on the project page or in a file if you've downloaded it ;)
Hope this help!
P.S.: Thanks a lot to Lasha Dolidze to provide this code!
PINCode 1.0