Sunday, June 2, 2013

UITextField UITextFieldViewModeNever example in Objective C (iOS).


UITextField UITextFieldViewModeNever

UITextFieldViewMode
Defines the times at which overlay views appear in a text field.

typedef enum {
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
} UITextFieldViewMode;

Constants
UITextFieldViewModeNever
The overlay view never appears.
UITextFieldViewModeWhileEditing
The overlay view is displayed only while text is being edited in the text field.
UITextFieldViewModeUnlessEditing
The overlay view is displayed only when text is not being edited.
UITextFieldViewModeAlways
The overlay view is always displayed.

UITextField UITextFieldViewModeNever example.
UITextField *f = [[[UITextField alloc] init] autorelease];
f.frame = CGRectMake(0, 0, 300, 44);
f.backgroundColor = [UIColor clearColor];
f.textColor = [UIColor whiteColor];

f.clearButtonMode = UITextFieldViewModeNever;

Example of [UITextField UITextFieldViewModeNever].
  UITextField *txfSearchField = [searchbar valueForKey:@"_searchField"];
[txfSearchField setBackgroundColor:[UIColor whiteColor]];
    [txfSearchField setLeftView:UITextFieldViewModeNever];
    [txfSearchField setBorderStyle:UITextBorderStyleRoundedRect];
    txfSearchField.layer.borderWidth = 8.0f;
    txfSearchField.layer.cornerRadius = 10.0f;
        txfSearchField.layer.borderColor = [UIColor clearColor].CGColor;

UITextField UITextFieldViewModeNever example.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifierForSection0 = @"Cell0";
    static NSString *CellIdentifierForSection1 = @"Cell1";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: [indexPath section] == 0 ? CellIdentifierForSection0 : CellIdentifierForSection1];
    if (cell == nil) {

        if ([indexPath section] == 0) { // Email & Password Section

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:CellIdentifierForSection0];
            cell.textLabel.text = @"Subject";

            UITextField *subject = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
            subject.adjustsFontSizeToFitWidth = YES;
            subject.textColor = [UIColor blackColor];
            if ([indexPath row] == 0) {
                subject.placeholder = @"Maths";
                subject.keyboardType = UIKeyboardTypeEmailAddress;
                subject.returnKeyType = UIReturnKeyNext;
            }
            subject.backgroundColor = [UIColor clearColor];
            subject.autocorrectionType = UITextAutocorrectionTypeNo;
            subject.autocapitalizationType = UITextAutocapitalizationTypeWords;
            subject.tag = 0;
            subject.clearButtonMode = UITextFieldViewModeNever;
            [cell.contentView addSubview:subject];
        } else {

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:CellIdentifierForSection1];
            cell.textLabel.text = @"Task";

            UITextView *task = [[UITextView alloc] initWithFrame:CGRectMake(102, 0, 185, 40)];
            task.text = @"fasfashfjasfhasfasdjhasgdgasdhjagshjdgashjdgahjsdghjasgasdashgdgjasd";
            task.editable = NO;
            task.scrollEnabled = NO;
            task.userInteractionEnabled = NO;
            task.textColor = [UIColor colorWithRed: 62.0/255.0 green: 85.0/255.0 blue:132.0/255.0 alpha:1.0];
            task.backgroundColor = [UIColor clearColor];
        }

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    return cell;
}

End of UITextField UITextFieldViewModeNever example article.