IOS uitextview行距和UITextFiled的区别

正在播放:iOS开发视频教程-UI第1季-2.14-UITextView和UITextField的区别
下载学院iPad端缓存视频离线看
记录时间点
我的笔记同学的笔记
我的问题同学的问题更多内容如下:
Powered by
& 2013 &&&IOS UITextView和UITextFiled的区别_百度知道
IOS UITextView和UITextFiled的区别
提问者采纳
UITextview支持多行输入 UITextFiled只支持单行UITextview没有placeholder属性 UItextField有placeholder属性继承也不一样 UITextview继承UIScrollerView UItextField继承UIview
其他类似问题
ios的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁网站导航:
您现在的位置: >
> 浏览信息
IOS键盘挡住UITextView的解决方案
时间: 11:18
来源: 作者:学盟网
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
- (void)unregisterForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- (void)viewWillAppear:(BOOL)animated {
[self registerForKeyboardNotifications];
_viewFrame = _inputDiaryView.
- (void)viewDidDisappear:(BOOL)animated {
[self unregisterForKeyboardNotifications];
- (void)keyboardWasShown:(NSNotification *)aNotification {
CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView beginAnimations:TEXTVIEW_KEYBOARD context:nil];
[UIView setAnimationDuration:animationDuration];
_inputDiaryView.frame = CGRectMake(0, _viewFrame.origin.y - keyboardRect.size.height, _viewFrame.size.width, _viewFrame.size.height);
[UIView commitAnimations];
- (void)keyboardWillBeHidden:(NSNotification *)aNotification{
NSTimeInterval animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView beginAnimations:TEXTVIEW_KEYBOARD context:nil];
[UIView setAnimationDuration:animationDuration];
_inputDiaryView.frame = _viewF
[UIView commitAnimations];
本文来自学盟网()
_viewFrame:是UITextView的父控件的frame 本文来自学盟网()
_inputDiaryView就是UITextView的父控件 内容来自学生黑客联盟
学生黑客联盟
本文标题:
本文地址:
免责声明:本文仅代表作者个人观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
下一篇:没有了SlackTextViewController-master
InfoPlist.strings
Images.xcassets
AppIcon.appiconset
Contents.json
icn_append.imageset
Contents.json
icn_append.png
icn_append@2x.png
icn_editing.imageset
Contents.json
icn_editing.png
icn_editing@2x.png
icn_network.imageset
Contents.json
icn_network.png
icn_network@2x.png
icn_typing.imageset
Contents.json
icn_typing.png
icn_typing@2x.png
icn_upload.imageset
Contents.json
icn_upload.png
icn_upload@2x.png
LaunchImage.launchimage
Contents.json
Default-568@2x.png
Default-hd-plus@2x.png
Default-hd-plus@2x~landscape.png
Default-hd@2x.png
Default@2x.png
Messenger-Info.plist
Messenger-Prefix.pch
Messenger.xcodeproj
project.xcworkspace
xcshareddata
Messenger.xccheckout
contents.xcworkspacedata
xcuserdata
libinggen.xcuserdatad
Messenger.xcscheme
xcschememanagement.plist
project.pbxproj
Messenger.xcworkspace
xcshareddata
Messenger.xccheckout
xcuserdata
libinggen.xcuserdatad
UserInterfaceState.xcuserstate
contents.xcworkspacedata
BuildHeaders
LoremIpsum
SlackTextViewController
LoremIpsum
SlackTextViewController
Local Podspecs
SlackTextViewController.podspec
LoremIpsum
LoremIpsum
License.markdown
Readme.markdown
Pods.xcodeproj
xcuserdata
libinggen.xcuserdatad
Pods-LoremIpsum.xcscheme
Pods-SlackTextViewController.xcscheme
Pods.xcscheme
xcschememanagement.plist
project.pbxproj
Manifest.lock
Pods-acknowledgements.markdown
Pods-acknowledgements.plist
Pods-LoremIpsum-prefix.pch
Pods-LoremIpsum-Private.xcconfig
Pods-LoremIpsum.xcconfig
Pods-resources.sh
Pods-SlackTextViewController-prefix.pch
Pods-SlackTextViewController-Private.xcconfig
Pods-SlackTextViewController.xcconfig
Pods.xcconfig
Podfile.lock
Screenshots
screenshot_auto-completion.png
screenshot_auto-expanding.png
screenshot_edit-mode.png
screenshot_shake-undo.png
screenshot_typing-indicator.png
slacktextviewcontroller_demo.gif
UIKeyboard_constants.txt
.gitignore
SlackTextViewController.podspec
SlackTextViewController-master
._InfoPlist.strings
Images.xcassets
AppIcon.appiconset
._Contents.json
icn_append.imageset
._Contents.json
._icn_append.png
._icn_append@2x.png
icn_editing.imageset
._Contents.json
._icn_editing.png
._icn_editing@2x.png
icn_network.imageset
._Contents.json
._icn_network.png
._icn_network@2x.png
icn_typing.imageset
._Contents.json
._icn_typing.png
._icn_typing@2x.png
icn_upload.imageset
._Contents.json
._icn_upload.png
._icn_upload@2x.png
._icn_append.imageset
._icn_editing.imageset
._icn_network.imageset
._icn_typing.imageset
._icn_upload.imageset
LaunchImage.launchimage
._Contents.json
._Default-568@2x.png
._Default-hd-plus@2x.png
._Default-hd-plus@2x~landscape.png
._Default-hd@2x.png
._Default@2x.png
._AppIcon.appiconset
._LaunchImage.launchimage
._en.lproj
._Images.xcassets
._Messenger-Info.plist
._Messenger-Prefix.pch
Messenger.xcodeproj
project.xcworkspace
xcshareddata
._Messenger.xccheckout
._contents.xcworkspacedata
._xcshareddata
._project.pbxproj
._project.xcworkspace
Messenger.xcworkspace
xcshareddata
._Messenger.xccheckout
._contents.xcworkspacedata
._xcshareddata
BuildHeaders
SlackTextViewController
._Additions
._LoremIpsum
._SlackTextViewController
SlackTextViewController
._Additions
._LoremIpsum
._SlackTextViewController
Local Podspecs
._SlackTextViewController.podspec
LoremIpsum
LoremIpsum
._License.markdown
._LoremIpsum
._Readme.markdown
._BuildHeaders
._Local Podspecs
._LoremIpsum
._Manifest.lock
._Pods-acknowledgements.markdown
._Pods-acknowledgements.plist
._Pods-LoremIpsum-prefix.pch
._Pods-LoremIpsum-Private.xcconfig
._Pods-LoremIpsum.xcconfig
._Pods-resources.sh
._Pods-SlackTextViewController-prefix.pch
._Pods-SlackTextViewController-Private.xcconfig
._Pods-SlackTextViewController.xcconfig
._Pods.xcconfig
._Pods.xcodeproj
._.DS_Store
._Messenger
._Messenger.xcodeproj
._Messenger.xcworkspace
._Podfile.lock
._.DS_Store
._Messenger
Screenshots
._screenshot_auto-completion.png
._screenshot_auto-expanding.png
._screenshot_edit-mode.png
._screenshot_shake-undo.png
._screenshot_typing-indicator.png
._slacktextviewcontroller_demo.gif
._UIKeyboard_constants.txt
._.DS_Store
._Additions
._.DS_Store
._.gitignore
._Examples
._README.md
._Screenshots
._SlackTextViewController.podspec
._SlackTextViewController-master
Copyright 2014 Slack Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the &License&);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an &AS IS& BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
// 鐗堟潈灞炰簬鍘熶綔鑰?//
(cn) http://code4app.net (en)
// 鍙戝竷浠g爜浜庢渶涓撲笟鐨勬簮鐮佸垎浜?綉绔?
#import &UITextView+SLKAdditions.h&
@implementation UITextView (SLKAdditions)
- (NSUInteger)numberOfLines
return abs(self.contentSize.height/self.font.lineHeight);
- (void)scrollToCaretPositonAnimated:(BOOL)animated
if (!animated)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.0];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[self scrollRangeToVisible:self.selectedRange];
[UIView commitAnimations];
[self scrollRangeToVisible:self.selectedRange];
- (void)scrollToBottomAnimated:(BOOL)animated
CGRect rect = [self caretRectForPosition:self.selectedTextRange.end];
rect.size.height += self.textContainerInset.
if (!animated)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.0];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[self scrollRectToVisible:rect animated:animated];
[UIView commitAnimations];
[self scrollRectToVisible:rect animated:animated];
- (void)insertNewLineBreak
[self insertTextAtCaretRange:@&\n&];
BOOL animated = YES;
SEL expandingSelector = NSSelectorFromString(@&isExpanding&);
if ([self respondsToSelector:expandingSelector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored &-Warc-performSelector-leaks&
BOOL isExpanding = (BOOL)[self performSelector:expandingSelector withObject:nil];
#pragma clang diagnostic pop
// if the text view cannot expand anymore, scrolling to bottom are not animated to fix a UITextView issue scrolling twice.
animated = !isE
//Detected break. Should scroll to bottom if needed.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0025 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self scrollToBottomAnimated:animated];
- (void)insertTextAtCaretRange:(NSString *)text
NSRange range = [self insertText:text inRange:self.selectedRange];
self.selectedRange = NSMakeRange(range.location, 0);
- (NSRange)insertText:(NSString *)text inRange:(NSRange)range
// Skip if the text is empty
if (text.length == 0) {
return NSMakeRange(0, 0);
// Append the new string at the caret position
if (range.length == 0)
NSString *leftString = [self.text substringToIndex:range.location];
NSString *rightString = [self.text substringFromIndex: range.location];
self.text = [NSString stringWithFormat:@&%@%@%@&, leftString, text, rightString];
range.location += [text length];
// Some text is selected, so we replace it with the new text
else if (range.length & 0)
self.text = [self.text stringByReplacingCharactersInRange:range withString:text];
return NSMakeRange(range.location+[self.text rangeOfString:text].length, text.length);
// No text has been inserted, but still return the caret range
return self.selectedR
- (NSString *)wordAtCaretRange:(NSRangePointer)range
return [self wordAtRange:self.selectedRange rangeInText:range];
- (NSString *)wordAtRange:(NSRange)range rangeInText:(NSRangePointer)rangePointer
NSString *text = self.
NSInteger location = range.
if (text.length == 0) {
*rangePointer = NSMakeRange(0.0, 0.0);
NSString *leftPortion = [text substringToIndex:location];
NSArray *leftComponents = [leftPortion componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *leftWordPart = [leftComponents lastObject];
NSString *rightPortion = [text substringFromIndex:location];
NSArray *rightComponents = [rightPortion componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *rightPart = [rightComponents firstObject];
if (location & 0) {
NSString *characterBeforeCursor = [text substringWithRange:NSMakeRange(location-1, 1)];
if ([characterBeforeCursor isEqualToString:@& &]) {
// At the start of a word, just use the word behind the cursor for the current word
*rangePointer = NSMakeRange(location, rightPart.length);
return rightP
// In the middle of a word, so combine the part of the word before the cursor, and after the cursor to get the current word
*rangePointer = NSMakeRange(location-leftWordPart.length, leftWordPart.length+rightPart.length);
NSString *word = [leftWordPart stringByAppendingString:rightPart];
// If a break is detected, return the last component of the string
if ([word rangeOfString:@&\n&].location != NSNotFound) {
*rangePointer = [text rangeOfString:word];
word = [[word componentsSeparatedByString:@&\n&] lastObject];
Copyright(C)
OKBASE.NET All Rights Reserved 好库网 版权所有

我要回帖

更多关于 uitextview字数限制 的文章

 

随机推荐