Please take a look of the following screen shot.
alt text http://img442.imageshack.us/img442/8027/img0402k.png
Here is my code, I am using cocos2D
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
_view = [[CCDirector sharedDirector]openGLView];
// Input the user name
_nameField = [[UITextField alloc]initWithFrame:CGRectMake(130.0, 270.0, 200.0, 30.0)];
_nameField.transform = transform;
_nameField.adjustsFontSizeToFitWidth = YES;
_nameField.textColor = [UIColor blackColor];
[_nameField setFont:[UIFont fontWithName:#"Arial" size:14]];
_nameField.placeholder = #"<Enter Your Name>";
_nameField.backgroundColor = [UIColor clearColor];
_nameField.autocorrectionType = UITextAutocorrectionTypeNo;
_nameField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
_nameField.textAlignment = UITextAlignmentCenter;
_nameField.keyboardType = UIKeyboardTypeDefault;
_nameField.returnKeyType = UIReturnKeyDone;
_nameField.tag = 0;
_nameField.delegate = self;
_nameField.clearButtonMode = UITextFieldViewModeNever;
_nameField.borderStyle = UITextBorderStyleRoundedRect;
[_view addSubview:_nameField];
The problem is the text is aligned to the top of the text field.
I want it to be in the middle not to top. There is too much space in the bottom.
please suggest me the way.
Shouldn't this work?
_nameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Related
I saw a this question and answer and I tried a few options but non worked.
I would like to create a UIPickerView like the one below, (fixed labels inches and feet) but those wouldn't appear:
I create the UIImagePicker like this:
- (void)viewDidLoad
{
_picker = [[UIPickerView alloc] init];
CGRect pickerFrame = CGRectMake(0, 0, 200, 216);
pickerView.frame = pickerFrame;
pickerView.userInteractionEnabled = YES;
pickerView.dataSource = self;
pickerView.hidden = YES;
pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;
[self.view addSubview:pickerView];
[textField setInputView:pickerView];
textField.delegate = self;
[pickerView removeFromSuperview];
_picker.hidden = YES;
}
- (BOOL) textFieldShouldBeginEditing:(UITextView *)textView
{
if (textView.tag==1){ //field for the uipickerview
_picker.hidden = NO;
[self addPickerLabel:#"Feet" rightX:114 top:342 height:21];
[self addPickerLabel:#"Inches" rightX:241 top:342 height:21];
}
return YES;
}
- (void)addPickerLabel:(NSString *)labelString rightX:(CGFloat)rightX top:(CGFloat)top height:(CGFloat)height {
#define PICKER_LABEL_FONT_SIZE 18
#define PICKER_LABEL_ALPHA 0.7
UIFont *font = [UIFont boldSystemFontOfSize:PICKER_LABEL_FONT_SIZE];
CGFloat x = rightX - [labelString sizeWithFont:font].width;
// White label 1 pixel below, to simulate embossing.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, top + 1, rightX, height)];
label.text = labelString;
label.font = font;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
label.alpha = PICKER_LABEL_ALPHA;
[_picker addSubview:label];
// Actual label.
label = [[UILabel alloc] initWithFrame:CGRectMake(x, top, rightX, height)];
label.text = labelString;
label.font = font;
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
label.alpha = PICKER_LABEL_ALPHA;
[_picker addSubview:label];
}
The picker appears, but without the fixed labels of inches and feet.
What is wrong?
Move this lines to viewDidLoad and try it.Labels need to be added
once.Not always when textfield did begin editing
[self addPickerLabel:#"Feet" rightX:114 top:342 height:21];
[self addPickerLabel:#"Inches" rightX:241 top:342 height:21];
Log the frame of both the label and set it correct if it appears wrong
NSLog(#"%#",NSStringFromCGRect(label.frame));
Your UIPickerView has height of 216, but you put the labels at height 342. This might be the reason you can't see them.
Edit:
Try replacing the lines where you make the labels to
[self addPickerLabel:#"Feet" rightX:114 top:98 height:21];
[self addPickerLabel:#"Inches" rightX:241 top:98 height:21];
I used the already implemented great component:
https://github.com/brunow/ActionSheetPicker2
Which provides a multicolumn picker view and I simply changed the text and the amount of columns
i am writing this code to load a plist into 2 textview but i want them to adjust their height according to content size which i have done but i want the second uitextview to start from where the first one ends .. please help
for (int i = 0; i < arrresult.count; i++) {
NSArray *sorteddetail = [self.arrresult sortedArrayUsingFunction:sortint context:NULL];
DuaObject *duaobj2 = [[DuaObject alloc] initWithFilePath:[sorteddetail objectAtIndex:i]];
[duaobj2 loadFile];
CGRect frame;
frame.origin.x = self.scrollmain.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollmain.frame.size;
UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)];
UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)];
subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BG_text.png"]];
subview2.backgroundColor = [UIColor whiteColor];
[subview setFont:[UIFont boldSystemFontOfSize:14]];
[subview2 setFont:[UIFont boldSystemFontOfSize:14]];
subview.layer.cornerRadius = 10 ;
subview2.layer.cornerRadius = 10;
NSString *p = [duaobj2 dua_arabic];
NSString *b = [duaobj2 eng_trans];
subview.text = p;
subview2.text = b;
[self.scrollmain addSubview:subview];
[self.scrollmain addSubview:subview2];
subview.editable = NO;
subview2.editable = NO;
subview.textColor = [UIColor blackColor];
subview2.textColor = [UIColor blackColor];
subview.backgroundColor = [UIColor whiteColor];
subview2.backgroundColor = [UIColor whiteColor];
scrollmain.showsHorizontalScrollIndicator = NO;
CGRect frame1 = subview.frame;
CGRect frame2 = subview2.frame;
frame1.size.height = subview.contentSize.height;
frame2.size.height = subview2.contentSize.height;
subview.frame = frame1;
subview2.frame = frame2;
}
You can use two UIWebView for this. After fetching text data from plist ,redirect it on particular web view. and use [webView stringByEvaluatingJavaScriptFromString:#"document.body.offsetHeight;"] method to get height in pixel. According to height of pixel you can re-adjust web views frame.
Edit:
Look this one : How do I size a UITextView to its content?
It will help you.
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)];
How i can display vertical pages for UITextView in UIScrollview
self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 410)]autorelease];
self.textView.textColor = [UIColor blackColor];
self.textView.font = [UIFont fontWithName:#"Georgia-Bold" size:14];
self.textView.textAlignment = UITextAlignmentCenter;
//self.textView.backgroundColor = [UIColor colorWithHue:2.0/12 saturation:2.0 brightness:4.0/10 alpha:1.0];
self.textView.backgroundColor = [UIColor whiteColor];
self.textView.editable = NO;
self.textView.delegate = self;
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.layer.borderWidth = 1;
self.textView.layer.borderColor = [[UIColor darkGrayColor] CGColor];
self.textView.layer.cornerRadius = 1;
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.text = #"Juice fasting makes every other natural method work faster...............";
[self.view addSubview:self.textView];
scrollView.contentSize = CGSizeMake(textView.frame.size.width, textView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 0.75;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.delegate = self;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
[self.scrollView addSubview:self.textView];
[button release];
[super viewDidLoad];
}
I have a long text in UITextView. How i can display this UITextView in vertical pages when user scrolls.
Appreciate help.
Did you try paging?
textView.pagingEnabled = YES;
Is that what you want? Otherwise I probably would recommend using a default UILabel in a default UIScrollView, to set this up. (Adding one UILabel per page to the scrollView)
Make the text view large enough so that there is no scrolling within it (or change it to a UILabel), and put that inside a separate scrollView.
Then set
scrollView.pagingEnabled = YES;
and make sure the height of the content size is larger than the height of the actual scroll view. So if the text view is 320x960, make the scroll view 320x480.
I have this textField
who doing text on center?///////////////////////////////////
textPredmet = [[UITextField alloc] initWithFrame:CGRectMake(20, 55, 200, 40)];
textPredmet.borderStyle = UITextBorderStyleNone;
textPredmet.textColor = [UIColor blackColor]; //text color
textPredmet.font = [UIFont systemFontOfSize:15.0]; //font size
[textPredmet drawTextInRect:CGRectMake( 30,55,200,40)];
textPredmet.placeholder = #"Введите текст"; //place holder
textPredmet.backgroundColor = [UIColor clearColor]; //background color
textPredmet.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textPredmet.keyboardType = UIKeyboardTypeDefault; // type of the keyboard
textPredmet.returnKeyType = UIReturnKeyDone; // type of the return key
textPredmet.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textPredmet.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
textPredmet.background = [UIImage imageNamed:#"input.png"];
textPredmet.textAlignment=UITextAlignmentLeft+1;
[self.view addSubview:textPredmet];
Set below line to your code.
textPredmet.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
It will set the text center vertically.
textPredmet.textAlignment = UITextAlignmentCenter;
It will set the text center horizontally.
Also, remove below lines from your code.
[textPredmet drawTextInRect:CGRectMake( 30,55,200,40)];
I guess, UITextAlignmentLeft+1 == UITextAlignmentCenter