저는 현재 내 앱에서 일종의 브라우저를 구현하는 중입니다. 그러나 iOS 프로그래밍에 익숙하지 않기 때문에 프로그래밍 방식으로 텍스트 필드의 너비를 변경하는 방법을 알지 못합니다. 현재 구현에서 일어나는 일은 텍스트 필드가 내비게이션 컨트롤러의 뒤로 버튼을 넘는 것입니다. 따라서 왼쪽에 공간을 남기려면 텍스트 필드가 필요합니다.UITextField 너비를 변경 하시겠습니까?
누구든지이 작업을 수행하는 방법을 알고 있습니까? 이것은 가능한가?
/* Create the page title label */
UINavigationBar *navBar = self.navigationController.navigationBar;
CGRect labelFrame = CGRectMake(kMargin, kSpacer,
navBar.bounds.size.width - 2*kMargin, kLabelHeight);
UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:12];
label.textAlignment = NSTextAlignmentCenter;
[navBar addSubview:label];
self.pageTitle = label;
/* Create the address bar */
CGRect addressFrame = CGRectMake(kMargin, kSpacer*2.0 + kLabelHeight,
labelFrame.size.width, kAddressHeight);
UITextField *address = [[UITextField alloc] initWithFrame:addressFrame];
address.autoresizingMask = UIViewAutoresizingFlexibleWidth;
address.borderStyle = UITextBorderStyleRoundedRect;
address.font = [UIFont systemFontOfSize:17];
address.keyboardType = UIKeyboardTypeURL;
address.autocapitalizationType =UITextAutocapitalizationTypeNone;
address.autocorrectionType = UITextAutocorrectionTypeNo;
address.clearButtonMode = UITextFieldViewModeWhileEditing;
[address addTarget:self
action:@selector(loadRequestFromAddressField:)
forControlEvents:UIControlEventEditingDidEndOnExit];
[navBar addSubview:address];
self.addressField = address;
또 다른 질문입니다. 보기가 변경되면 (탐색 컨트롤러 뒤로 버튼) 주소 표시 줄이 사라지지 않습니다. 어떻게해야합니까? – user4114789