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.
Related
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.
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.
I've added custom background image to my UITableView and it shows fine. Than, i removed any background color from the cells. Now i expect to see only cells' text on top of table's background image, however i see strange behaviour. Cells take pattern color of table's background image, so that i see waves like in the picture:
The background image shell look like this:
*pay attention to white circles that disappear under the cells!
My code is as follws:
in viewDidLoad i set the background image of table view:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"general_bg.png"]];
For each cell i remove any background color like this:
UIView *bckView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bckView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bckView;
cell.backgoundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,y,x1,y1)];
textLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:textLabel];
line separators are custom images added to cells.
Instead of setting the BackgroundColor attribute of the tableview, try setting the backgroundview:
UIView *background = [[UIView alloc] initWithFrame:self.tableView.bounds];
background.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
self.tableView.backgroundView = background;
This should fix the issue of the cell's taking on the same image as the background.
self.tableView.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
maybe this is what you're looking for
I am working on a table under iOS, I added a couple of cells, and each cell has one UITextField added as a subview. An excerpt:
UITextField *t = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 5.0, 220.0, 20.0)];
// here I set properties for t ...
t.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
[cell addSubview:t];
cell.autoresizeSubviews = YES;
// if needed, I set the UIImageView for the cell
if (...) {
cell.imageView.image = [UIImage imageNamed:#"myimage.png"];
t.frame = CGRectOffset(text.frame, 33, 0);
}
[t release];
What happens? When I enter the editing mode for the tabel, I'd expect that each cell will resize to make the red minus sign visible, and that the UITextField will move to right to remain aligned to the cell itself, as the other components. But this do not happen.
Also, I tried to change the autoresizingMask param using various combinations of UIViewAutoresizingFlexibleLeftMargin, UIViewAutoresizingFlexibleRightMargin and UIViewAutoresizingFlexibleWidth, but without success.
Am I doing something wrong here? Should I change the way I add the text field as a subview?
Thank you!
add your views to the contentView of the cell:
[cell.contentView addSubview:t];
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!