Placing an image in the bottom of an UITextfield as background - iphone

After a lot of search I am posting this Question, I have to place an image at the bottom of a UITextfield, I have tried it with the following code :
letterField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
letterField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
letterField.textAlignment = UITextAlignmentCenter;
letterField.borderStyle = UITextBorderStyleNone;
UIImageView *myView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"text_line.png"]];
[letterField setLeftView:myView];
[letterField setRightViewMode:UITextFieldViewModeAlways];
[myView release];
// letterField.background = [UIImage imageNamed:#"text_line.png"];
// [letterField setBackground:[UIImage imageNamed:#"text_line.png"]];
letterField.textColor = [UIColor whiteColor];
letterField.returnKeyType = UIReturnKeyDone;

[yourtextfield insertSubview:imgViewTitleBackGround atIndex:0];// mgViewTitleBackGround is image view with background image.
//Or
[yourtextfield setBackground:[UIImage imageNamed:#"text_line.png"]];// you can add your image
yourtextfield.textColor = [UIColor redColor];
Hope, this will help you..enjoy

Sorry, my previous answer was totally wrong. From what I can see your image is text_line.png - i suppose it's some kind of separator line, what can i suggest you to try is create a new UIView with the bounds of the UITextField, then add the text field inside this view and add the UIImage view again as subview of this view centering it properly. I don't know if this will fit your needs, but you can give it a try.

Related

How to put an image and write text in same UILabel?

I want to put an image in my UILabel which should be right aligned and write some text in the same UILabel which should be left aligned. How can i do that programatically? Thanks in advance
Set that image as background image
theLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"blah"]];
and write text as
thelabel.text = #"abc"
set the align of the label
[thelabel setTextAlignment:UITextAlignmentLeft];
I am not sure that you can actually put an image inside a UILabel, but if you can, you'll be using the addSubView: method.
UILabel *label = ....
label.text = #"Hi there";
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,width,height)];
[label addSubView:image];
Try it out and see if it works, if not, then you'll probably have to set the image's frame to a frame that floats along with the label's.

Text is not getting placed as mentioned in CGRect frame of UILable

this might look simple but i am not able to Find the solution for this...when i use this below code the text get placed at right postion as mentioned in the CGRect frame.
[self.view addSubview:[self createLabel:CGRectMake(50,480,50,20):#"Status:"]];
-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
[UIFont fontWithName:#"Arial" size:13];
myLabel.textAlignment = UITextAlignmentLeft;
}
But when i use this below Code the text is getting placed at rightmost corner of the frame...its not getting placed at right position as mentioned in the CGRect frame..can anyone tell whats the problem happening with this..
[self.view addSubview:[self createLabel:CGRectMake(50,340,150,20):aRequests.request_details]];
NOTE:aRequests.request_details is coming from webservices..
Your method doesn't return any object. Try to add return myLabel; at the end of it.
And you are not setting new title: myLabel.text = labelTitle;

custom UITextField with image as a background blinking cursor issue

I have a custom UITextField with a UIImage as a background. Now when I type in a text into this UITextField and the cursor is blinking I get this:
I don't want to have a white image on the cursor blinking as it destroys the aesthetics.
I tried playing around with this and tried setting the background view to have the same color as the image, however the issue is that the UITextField shape is always a rectangle. How do I solve this?
Have you tried setting textField.backgroundColor = [UIColor clearColor]?
You can use a UIImageView for the image and then add a UITextField as a subview with clear background. Just create UIImageView *imageView and UITextField *textField, either programmatically or in the IB. If you go programmatically, use [imageView addSubview:textField]; and set the frame as you like. In the IB, just drop the textField onto the imageView and align it as you like.
I just tried it. It does not have the cursor highlighted like that.
set
textField.backgroundColor = [UIColor brownColor] // or your color
and
textField.textColor = [UIColor whiteColor];
For adding the textField into the UIView ;
//Do this where you create the UIView* view
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.clearsOnBeginEditing = NO;
textField.textAlignment = UITextAlignmentRight;
textField.returnKeyType = UIReturnKeyDone;
textField.textColor = [UIColor blackColor]; // or any other color
textField.font = [UIFont systemFontOfSize:15];
textField.delegate = self;
[view addSubview:textField];
What about creating a UIImageView with your image in it, and then embedding a borderless UITextField inside your image view? The text field will still be editable, but shouldn't interfere with the imageview behind it.

Background on UITableView?

How to show Background image in UITableView Like
Please help me out. Thank you
Use this
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"cloud.png"] ];
self.tableView.backgroundView = imageView;
[imageView release];
self.tableView.backgroundColor = [UIColor clearColor];
Add an UIImageView to the View, ontop of that place the UITableView and set the background color to clearcolor.
You can also go ahead and set the background color directly:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"image.jpg"]];

ios uitextfield like notes

I wish that my uitextfield seems like the notes of the iPhone, yellow with the lines..
what's the best way to do this?
thanks in advance!
You mean UItextview right? ... its not a UITextField.
However, clear your background on the UITextView.
self.textView.backgroundColor = [UIColor clearColor];
Then create ImageView that u put as a subview to your textview.
backgroundimage = [[UIImageView alloc] initWithFrame: CGRectMake(0, -14,textView.frame.size.width, textView.fram.size.height)];
set a pattern image as backgroundColor. This will be your lines. Just create on or two lines . Then it should repeat itself.
backgroundimage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"lines.png"];
then add your subview to the textview.
[self.textView addSubview:backgroundimage];
Good luck!