I can't comprehend it. I have a uitextview which animates upward when it begins editing to make room for the keyboard. I tap the uitextview and registers that it has begun editing and it animates up but the keyboard doesn't appear. This has never happened before and I've tested the app hundreds of times. I even have the textview become first responder upon building the view and the keyboard still doesn't show.
I have the .m file and .h file as so that is not the issue..
Here is the set up code:
self.addDescriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 470, 320, 100)];
[self.addDescriptionTextView setBackgroundColor:[UIColor colorWith8BitRed:0 green:0 blue:0 alpha:.5]];
[self.addDescriptionTextView setTextColor: [UIColor whiteColor]];
[self.addDescriptionTextView setFont:[UIFont fontWithName:#"Verdana" size:16]];
[self.addDescriptionTextView setDelegate:self];
self.addDescriptionTextView.textContainer.maximumNumberOfLines = 10;
[self.addDescriptionTextView.layoutManager textContainerChangedGeometry:self.addDescriptionTextView.textContainer];
[confirmView addSubview:self.addDescriptionTextView];
I ran your code on my iOS device and the keyboard came up,
Heres the viewDidLoad Code I ran,
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.addDescriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 470, 320, 100)];
self.addDescriptionTextView.backgroundColor = [UIColor redColor];
[self.addDescriptionTextView setTextColor: [UIColor whiteColor]];
[self.addDescriptionTextView setFont:[UIFont fontWithName:#"Verdana" size:16]];
[self.addDescriptionTextView setDelegate:self];
self.addDescriptionTextView.textContainer.maximumNumberOfLines = 10;
[self.addDescriptionTextView.layoutManager textContainerChangedGeometry:self.addDescriptionTextView.textContainer];
self.addDescriptionTextView.editable = YES;
[self.view addSubview:self.addDescriptionTextView];
}
Try adding the UIView.editable line but it should be set to yes automatically.
It might have something to do with confirmView?
Also try changing the UIColor Background colour line I was getting errors with your one.
Edit: After running on iPhone4s your problem is the position you initiate the UIView (to see try changing the 470 to 0 in the CGRect to see the bug)
Related
I have a UISearchBar whose bartintcolor i have changed and have cancel enabled. This is added as a subview of a UIVew.
whenever make search bar visible, it shows a black line below it which never goes away.
Am i missing something about UISearchbar appearence or its background view.
dummyview=[[UIView alloc]initWithFrame:CGRectMake(10, 30,self.headerView.frame.size.width-20, 30)];
[dummyview setBackgroundColor:[UIColor redColor]];
[dummyview setClipsToBounds:TRUE];
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, dummyview.frame.size.width, dummyview.frame.size.height)];
self.searchBar.delegate = (id)self;
[self.searchBar setPlaceholder:#"Search"];
self.searchBar.showsCancelButton = YES;
_searchBar.barTintColor = [Utilities colorWithHexString:#"3a7ebc"];
[[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor whiteColor]];
_searchBar.delegate=self;
[dummyview addSubview:_searchBar];
it gives me like this
if i change background to native one, i get displaced content.
// _searchBar.barTintColor = [Utilities colorWithHexString:#"3a7ebc"];
I just dont want the black line below the searchbar.
Updated:
using
_searchBar.searchBarStyle=UISearchBarStyleMinimal;
_searchBar.barStyle=UIBarStyleDefault;
result in this
So
finally everything done
_searchBar.searchBarStyle=UISearchBarStyleMinimal;
_searchBar.barStyle=UIBarStyleDefault;
UITextField *searchField=[_searchBar valueForKey:#"_searchField"];
if (searchField) {
[searchField setTextColor:[UIColor whiteColor]];
}
Put my code in viewdidload or viewwillappear method.
searchbar.barTintColor=[UIColor samebgcolor];
searchbar.layer.borderWidth = 1;
searchbar.layer.borderColor = [[UIColor samebgcolor] CGColor];
I would also consider, "I hope this will help you", as this is the strongest, and hopes that the thing will most definitely, certainly help.
If you like my Answer so accept and upvote my answer
I've programmatically created two UITextFields in my iOS app, and set their text to the _minPrice and _minPrice variables, respectively.
The _minPrice and _maxPrice values appear correctly in the two fields, but tapping on them doesn't allow the user to edit them, they just remain those static values, backspacing doesn't work. Is there anything about my code thats preventing the text fields from being edited?
// Min Price
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(-25, -76, 70, 30)];
tf.textColor = [UIColor blackColor];
tf.font = [UIFont fontWithName:#"Helvetica-Neue" size:14];
tf.backgroundColor=[UIColor whiteColor];
tf.text= _minPrice;
tf.textAlignment = NSTextAlignmentCenter;
tf.layer.cornerRadius=8.0f;
tf.layer.masksToBounds=YES;
tf.layer.borderColor=[[UIColor lightGrayColor]CGColor];
tf.layer.borderWidth= 1.0f;
// Max Price
UITextField *tf1 = [[UITextField alloc] initWithFrame:CGRectMake(100, -76, 70, 30)];
tf1.textColor = [UIColor blackColor];
tf1.font = [UIFont fontWithName:#"Helvetica-Neue" size:14];
tf1.backgroundColor=[UIColor whiteColor];
tf1.text= _maxPrice;
tf1.textAlignment = NSTextAlignmentCenter;
tf1.layer.cornerRadius=8.0f;
tf1.layer.masksToBounds=YES;
tf1.layer.borderColor=[[UIColor lightGrayColor]CGColor];
tf1.layer.borderWidth= 1.0f;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 400, 400)];
[view addSubview:tf];
[view addSubview:tf1];
[self.view addSubview:view];
Your issue is clearly the frames you're setting...
Setting the color of the view you add the labels to to blue reveals your problem:
If you ensure that the labels are actually within the view you add them to (i.e. not negative), editing will be fine. All I did was change the negative x and y values in tf to positive, and they were editable:
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(25, 76, 70, 30)];
Try this! Maybe there is another view at the top of the textField
your_textfield.userInteractionEnabled = YES;
If this doesn't work
add another line
[self.view bringSubviewToFront: your_textfield];
Try to add delegate methods on your textfields. Like
- (void) textFieldDidEndEditing:(UITextField *)textField
{
// ADD BREAKPOINT HERE.
}
Check if it goes to that line of code. If not maybe there's a view on top of it. Or you can try to bring textfield to front like .
[self.view bringSubviewToFront:yourTextfield];
But this isn't a good example of how you fix the problem. Just to test if there is a view on top of it.
I've created a UITextView instance and I'm trying to set its font:
UITextView *dummy = [[UITextView alloc] initWithFrame:self.frame];
dummy.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:14];//self.font;
However, at that second line, I'm getting EXC_BAD_ACCESS error, hitting continue execution doesn't do anything. It still hangs at the same line forever, with no error message at the console. It also used to throw at self.font too (I'm using the code inside a working UILabel and its font is a valid font object). Why am I getting this error?
UPDATE: I've also tried setText: it also throws the same too. Am I missing something obvious?
Try this code.
UITextView *textview =[[UITextView alloc]init];
textview.frame=CGRectMake(200, 10, 500, 50);
//To make the border look very close to a UITextField
[textview.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[textview.layer setBorderWidth:2.0];
textview.delegate=self;
//The rounded corner part, where you specify your view's corner radius:
textview.layer.cornerRadius = 5;
textview.clipsToBounds = YES;
[textview setFont:[UIFont fontWithName:#"Helvetica Neue" size:11]];
[textview setTextColor:[UIColor blueColor]];
[textview setReturnKeyType:UIReturnKeyDone];
I've found the solution.
I've tried [[UITextView alloc] initWithFrame:self.frame textContainer:nil]; instead of [[UITextView alloc] initWithFrame:self.frame]; and it worked. I don't understand why the other method didn't work, and this one works even though I'm using nil as the textContainer.
I have a label with numberOfLines set to 2, lineBreakMode set to NSLineBreakByTruncatingTail. I was expecting that when the text extends beyond two lines, the label will truncate it with ellipses. But what is happening is that although the text is being truncated no ellipses are getting shown.
Why would this be? Thanks.
More details:
Following is the custom class for the UITableViewCell that contains the label (contentLabel) in question. The labels are updated in the loadConversation method.
#interface CPActivityStreamCell ()
#property(nonatomic, weak) CardDeck *cardDeck;
#property(nonatomic, weak) UIImageView *icon;
#end
#implementation CPActivityStreamCell
#synthesize contentLabel, eventLabel, avatarView;
- (void)awakeFromNib {
[super awakeFromNib];
self.backgroundColor = [UIColor clearColor];
// Initialize views
[contentLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[contentLabel setNumberOfLines:2];
[contentLabel setTextAlignment:NSTextAlignmentLeft];
[contentLabel setTextColor:[UIColor colorWithWhite:0.55 alpha:1.0]];
contentLabel.backgroundColor = [UIColor clearColor];
[eventLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[eventLabel setNumberOfLines:1];
[eventLabel setTextAlignment:NSTextAlignmentLeft];
[eventLabel setTextColor:[UIColor colorWithWhite:0.55 alpha:1.0]];
eventLabel.backgroundColor = [UIColor clearColor];
eventLabel.font = [UIFont fontWithName:#"Antonio-Regular" size:12];
// Create the icon view
UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(20.0, 15.0, 16.0, 16.0)];
[self addSubview:icon];
self.icon = icon;
CardDeck *deck = [[CardDeck alloc] initWithFrame:self.contentView.frame numberOfCards:1];
self.backgroundView = deck;
self.cardDeck = deck;
}
- (void)loadConversation:(CPConversation *)conversation {
[self loadAvatars:conversation.avatarUrls];
self.contentLabel.textColor = [UIColor blackColor];
self.eventLabel.text = [conversation.eventTitle uppercaseString];
self.eventLabel.textColor = [UIColor colorWithWhite:0.55 alpha:1.0];
self.contentLabel.text = conversation.content;
[self loadEventTypeIcon:conversation.eventType white:NO];
[self updateDeck:conversation withFrame:self.contentView.frame];
if ([conversation.typeString isEqualToString:#"image"]) {
[self loadConversationImage:conversation];
}
}
//other methods
#end
The same label in IB:
Output:
The top cell's contentLabel is set to Start of a really long text to test truncation and display in activity stream. It should be truncated with ellipses. End.:
The problem lies somewhere in the architecture of your initialization procedure, or possibly in something you are doing elsewhere (in code you have not shown in your question). You are saying
[contentLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[contentLabel setNumberOfLines:2];
[contentLabel setTextAlignment:NSTextAlignmentLeft];
[contentLabel setTextColor:[UIColor colorWithWhite:0.55 alpha:1.0]];
contentLabel.backgroundColor = [UIColor clearColor];
But this code is not being applied to the label we see in the screen shot. That much is clear, because if it were being applied, the text would be a light gray color.
Thus we may conclude that this code is not running or, if it is running, contentLabel is not hooked up property (perhaps it is nil) and the label is unaffected by it.
Finally, I may point out that on my machine I simply ran your code as given, directly, on a UILabel (not in a table view or anything), and it worked:
[contentLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[contentLabel setNumberOfLines:2];
[contentLabel setTextAlignment:NSTextAlignmentLeft];
[contentLabel setTextColor:[UIColor colorWithWhite:0.55 alpha:1.0]];
contentLabel.backgroundColor = [UIColor clearColor];
contentLabel.text = #"Start of a really long text to test truncation and display in activity stream. It should be truncated with ellipses. End.";
Thus I suggest that either your code is not running or not being applied to the label, or that some other code is coming along and changing the line break mode for this label. It is always best to convince oneself that something works generally for an extremely simple case (like mine, in the preceding code) and then try to figure out why particular results seem to differ from that...
I am seeing that "Back" button title is missing when my screen title is big. I needed to show the entire title. Is there any workaround to this?
Please see attached the screenshot of navigation bar I see with long title.
Make your screen title smaller. You can take control of it by using a titleView that's a UILabel. The advantage is that you can set its size, and that it can truncate its text and/or make the text occupy two lines if the text is too big (rather than just growing, as the title does).
UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,170,35)];
[iv setBackgroundColor:[UIColor whiteColor]];
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 170, 35)];
_titleLabel.textAlignment = UITextAlignmentCenter;
[_titleLabel setFont:[UIFont boldSystemFontOfSize:16.0]];
[_titleLabel setBackgroundColor:[UIColor clearColor]];
[_titleLabel setTextColor:[UIColor blackColor]];
[_titleLabel setText:#""];
_titleLabel.clipsToBounds = false;
iv.clipsToBounds = false;
[iv addSubview:_titleLabel];
[self.navigationItem setTitleView:iv];
also you need
#property (strong, nonatomic) UILabel* titleLabel;