我想更改我在UITextField控件中设置的占位符文本的颜色,使其变黑.
我更喜欢这样做而不使用普通文本作为占位符,并且必须覆盖所有方法来模仿占位符的行为.
我相信如果我重写这个方法:
- (void)drawPlaceholderInRect:(CGRect)rect
Run Code Online (Sandbox Code Playgroud)
然后我应该能够做到这一点.但我不确定如何从此方法中访问实际的占位符对象.
我有一个应用程序,用户必须键入一个四位数的密码.所有数字必须彼此相距一定距离.
如果它PinTextField是一个子类,有没有办法做到这一点UIView?我知道ViewController你可以使用UITextFieldTextDidChangeNotification并为每个更改设置属性文本.通知似乎不起作用UIView.
另外,我想知道如果你想设置UITextField文本的字母间距,是否没有比为每次更新制作属性字符串更简单的方法?
正确的间距:
间距错误:
这是我的代码...
struct ContentView : View {
@State var showingTextField = false
@State var text = ""
var body: some View {
return VStack {
if showingTextField {
TextField($text)
}
Button(action: {
self.showingTextField.toggle()
}) {
Text ("Show")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想要的是当文本字段变为可见时,使文本字段成为第一响应者(即,获得焦点并弹出键盘)。
我希望能够检测是否有一些文本被更改,UITextField以便我可以启用a UIButton来保存更改.
我正在使用UITextView的text属性获得关键值观察的最糟糕时间.我可以成功添加观察者,我甚至可以删除同一个观察者.我有一个包含几个单元格的tableview - 一些有UITextFields,一些有UISegmentSelectors,另一个有UITextView.对于UITextView,我的核心数据对象(NSMangedObject的子类)EXCEPT成功观察到所有其余字段.我可以根据需要发布代码.
发布代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *UserProfileCellIdentifier = @"UserProfileCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
UserProfileCellIdentifier];
if (cell == nil)
{
[_tableCellsNib instantiateWithOwner:self options:nil];
switch (indexPath.row)
{
// UserName Row
case UserNameRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"UserNameLabel", @"User Profile TableView");
_textFieldCell.cellType = CellTypeNormal;
_textFieldCell.boundProperty = @"UserName";
_textFieldCell.tag = indexPath.row;
_textFieldCell.errorHandler = self;
_textFieldCell.boundControl = _textFieldCell.cellTextField;
[_textFieldCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellTextField.text" options:NSKeyValueObservingOptionNew context:NULL];
cell = _textFieldCell;
self.textFieldCell = nil;
break;
case PasswordRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"PasswordLabel", @"User Profile TableView"); …Run Code Online (Sandbox Code Playgroud) 在我的UIScrollView子类中,我正在观察帧更改:
[self addObserver:self forKeyPath:@"frame" options:0 context:NULL];
Run Code Online (Sandbox Code Playgroud)
我的observeValueForKeyPath:ofObject:change:context:实现如下:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self && [keyPath isEqualToString:@"frame"]) {
[self adjustSizeAndScale];
}
if ([UIScrollView instancesRespondToSelector:@selector(observeValueForKeyPath:ofObject:change:context:)]) {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; // Exception
}
}
Run Code Online (Sandbox Code Playgroud)
但是这个代码我得到了异常:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<WLImageScrollView: 0x733a440; baseClass = UIScrollView; frame = (0 0; 320 416); clipsToBounds = YES; layer = <CALayer: 0x7346500>; contentOffset: {0, 0}>: An -observeValueForKeyPath:ofObject:change:context: message was received but not …Run Code Online (Sandbox Code Playgroud) 如何在UITextView中检测用户输入字符?
例如:(在UITextView NOT UITextField中)
当用户输入字母"a"时,触发事件.当用户输入"do it"时,触发另一个事件.或输入"http://www.stackoverflow.com"触发事件.
谢谢
我想在用户按任何键盘键时检测到.
任何只在键入任何字符时调用的方法,而不是在显示键盘时调用的方法.
谢谢!!
我有一个UITextField特定于处理Date文本的子类.我有一个tableviewcell使用此文本字段:
let dateInput: DateTextField
Run Code Online (Sandbox Code Playgroud)
现在控制器需要初始化dateInput显示之前的文本,如下所示:
cell.dateInput.text = "01/29/2016"
Run Code Online (Sandbox Code Playgroud)
现在,我希望能够检测到从子类更改的文本,以便我可以更新内部日期变量,以便它与文本同步.
我实现了textfield委托方法,但只捕获用户所做的更改,而不是以编程方式.
当我以UITextView编程方式设置我这样:
[self.textView setText:@""];
委托方法textViewDidChange:不会被调用.有没有一种方法可以在不创建UITextView子类的情况下找到它?
ios ×8
objective-c ×5
iphone ×3
swift ×3
uitextfield ×3
uitextview ×2
cocoa-touch ×1
ios6 ×1
ipad ×1
nsdate ×1
swiftui ×1