我想创建相同的popUp,如图所示.这个popUp在iPhone中是默认的,但是如果我想用自己的消息进行自定义,我该如何创建呢?

我有多个UITextFields,我需要在键盘出现时向上移动视图.但我只需要3个底部字段,并且不希望移动顶部其他字段的视图.我使用这个代码,但是当用户点击每个字段时它的移动视图,而我只需要在用户点击2个底部字段时移动视图
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark - keyboard movements
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -115.0f; //set the -35.0f to your required value
self.view.frame = f;
}];
}
-(void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = 0.0f;
self.view.frame = f; …Run Code Online (Sandbox Code Playgroud) 在主视图中,我在UITableView另一个视图下面,textInputView包含a UITextField和a UIButton.
向上移动UIView包含UITextField,UIButton当键盘显示不起作用时.
-(void)animateTextField:(UITextField*)textField up:(BOOL)up
{
const int movementDistance = -224; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? movementDistance : -movementDistance);
[UIView beginAnimations: @"animateTextField" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
textInputView.frame = CGRectOffset(textInputView.frame, 0, movement);
[UIView commitAnimations];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
[self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField:textField up:NO];
}
Run Code Online (Sandbox Code Playgroud)
如果我用self.view它替换textInputView …
可以在UITextField做代码此UI单独或者我需要使用的图像或使用其他组件的呢?像按钮,标签。

在我的应用程序中,我有一个UILabel和UITextField.最初的UILabel文字为零.
只要用户在UITextField我的UILabel文本中输入一些文本,也会更新.
让我们说,当用户在输入一个UITextField我UILabel立刻显示出A,B在UITextField我的UILabel节目B等.
为了实现这种行为,我使用了shouldChangeCharactersInRange函数UITextFieldDelegate.但它始终落后于一个角色.说UITextFieldtext = qwerty我的UIlabel文字显示qwert
请帮助我,以便我可以UILabel在用户输入值时不断更新文本UITextField
这是我的代码
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
mylabel.text = textfield.text
return true
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含a的UIView UICollectionView,其中包含自定义单元格.这些自定义单元格包含a UILabel和a UITextField.自定义单元类的代码和UICollectionView委托方法之一是:
class DurationDayCells: UICollectionViewCell {
@IBOutlet weak var dayLabel: UILabel!
@IBOutlet weak var dayHourText: UITextField!
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return daysSet.count
}
func collectionView(collectionView: UICollectionView!,layout collectionViewLayout: UICollectionViewLayout!,sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize {
return CGSize(width: (self.durationCollectionView.frame.width/CGFloat(daysSet.count)), height:
self.durationCollectionView.frame.height)
}
Run Code Online (Sandbox Code Playgroud)
如您所见,这些单元格是根据大小动态创建和调整大小的daysSet.问题是当我点击单元格中的一个文本字段时键盘没有弹出(粉红色/红色视图是说的UIView):

我还有一个跟进问题,当我设法键盘显示(不知何故),它UIView完全阻止了粉红色/红色,是否有一种方法可以在UIView选择文本字段时将整体向上移动,这样键盘就不会阻挡它?
让我疯狂的一件事就是找到一件简单的事:Swift中的字符串长度.
不,你不能使用string.length
不,你不能使用string.characters.count
不,你不能使用string.count
唯一对我有用的是string.endIndex.然而,这对于简单的textField检查不起作用,例如
func textViewDidChange(textView: UITextView) {
if textView.text.endIndex > 20 {
setBorder(descriptionField, finished: true)
} else {
setBorder(descriptionField, finished: false)
}
}
Run Code Online (Sandbox Code Playgroud)
由于endIndex不是Int而且无法转换成.这整件事让我发疯,我不知道该怎么办.任何帮助,将不胜感激!
我对Swift很新,我遇到了一个我不知道如何解决的问题.所以,我UITextField在文本字段中有一个最多5个字符的限制,我在第五个字符上停止没有问题,但问题是我无法清除文本,因为清除按钮可能认为是一个字符在iOS中.
有人可以帮我解决这个问题吗?
这是我的代码:
func textField(textField: UITextField,
shouldChangeCharactersInRange range: NSRange,
replacementString string: String) -> Bool{
if let count = textField.text?.characters.count {
if count < 5 {
print("\(count)")
return true
}
else {
return false
}
}
return true
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我在导航控制器中有一个tableview控制器.此表只显示每行中的一个文本字段.在我的导航控制器中,我有一个"完成"导航项,它获取在文本字段中输入的所有值并显示下一个屏幕.
tableview控制器实现UITextFieldDelegte和textFieldDidEndEditing,以将每个文本字段的值存储在其数据源(字符串数组)中.在cellForRowAtIndexPath中,我还将文本字段的委托分配给自己.如果我点击不同的文本字段,这一切都很有效,我看到数据源是如何正确更新的.
我的问题是当我执行此序列时:在一个文本字段中键入一个值,然后点击"完成"导航项.我看到没有调用textFieldDidEndEditing,因此不存储该值.我也尝试过textFieldShouldReturn和textFieldShouldReturn,但没有.
我已经阅读了很多类似的帖子,我认为问题是prepareForSegue而不是textFieldDidEndEditing正在捕获"事件".如果这是正确的,我不知道如何处理这个,因为我不知道如何在点击完成时识别"最后编辑的文本字段"的indexPath.
另一个相关问题:我在调用textFieldDidEndEditing时看到了两种获取包含textfield的单元格的indexPath的方法:
1)textField.convertPoint + tableView.indexPathForRowAtPoint
2)tableView.indexPathForCell + textField.superview
两者似乎都没有差异(除了我刚才提到的问题).有什么方法比另一种更好?
非常感谢您的帮助!!!
PS:如果可能,请使用Swift代码!
您好我目前使用以下来验证密码,但我也想包括特殊字符.目前它只包含数字和字母.请帮忙.
- (BOOL)validatePassword:(NSString *) password{
NSString *ACCEPTABLE_CHARECTERS = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ACCEPTABLE_CHARECTERS] invertedSet];
NSString *filtered = [[password componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [password isEqualToString:filtered];
}
Run Code Online (Sandbox Code Playgroud) uitextfield ×10
ios ×9
swift ×4
objective-c ×3
keyboard ×1
menu ×1
string ×1
subview ×1
uibutton ×1
uikeyboard ×1
uilabel ×1
uitableview ×1