Tag: 文本

获取UITextView上特定行的文本

最终,我想知道UITextView中最后一个字符的位置。 我能够通过使用以下方法找出y位置: CGSize size = [textView.text sizeWithFont:textView.font constrainedToSize:CGSizeMake(textView.frame.size.width-16,10000)lineBreakMode:UILineBreakModeClip]; 但是为了得到x的位置,我需要从textview的最后一行获取文本。 我试图从textView.text中删除一个字符,直到size.height改变,以实现这一效果,但我意识到,并不总是等于我想要的,当linebreak被考虑到。 任何build议任何人? 我已经花了整整一天的时间来试图找出这一个…

在视图控制器之间传递数据 – iOS Xcode – 什么是好方法?

好吧,我会试着尽可能简单(当我试着问这个问题时,我似乎在chat.stackoveflow.com上运行)。 我想将文本从一个视图控制器中的文本传递给另一个视图控制器。 我应该使用一个Model类,并将textfield.text存储在Model。[h / m]文件中,然后让第二个视图控制器访问存储在模型中的数据? 基本上这是我所拥有的, ViewControllerWelcome.h @interface ViewControllerWelcome : UIViewController { } @property (weak, nonatomic) IBOutlet UITextField *textFieldUsername; ViewControllerWelcome.m UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; ViewControllerHome *home = (ViewControllerHome *)[storyboard instantiateViewControllerWithIdentifier:@"Home"]; NSString *username = _textFieldUsername.text; home.lblUSERNAME.text=username; [self presentModalViewController:home animated:YES]; ViewControllerHome.h @interface ViewControllerHome : UIViewController { NSString *username; UILabel *lblUSERNAME; } @property (weak, nonatomic) IBOutlet […]

如何根据帧的大小为UIScrollView / UITextView分离string

我目前正在尝试阅读一个RSS提要,并将分隔的长文本分隔为启用了分页的UIScrollView。 我需要将文本分成不同的页面,也就是适合每个页面的内容,并将string分开。 我不确定是否有一个标准的做法,我认为这是大多数RSS阅读应用程序分离他们的信息在多个页面上。 有谁知道如何解决这个问题? 我不想逐字逐字地看,直到文本不合适并继续。 编辑: 这是一个很好的开始,但是示例代码几乎遇到了我试图避免的问题,并且不知道如何解决。 这个范围计算不正确的UITextView。 我改变了字体,如下图所示。 一切都在尝试在 – (NSRange)visibleRangeOfTextView:(UITextView *)textView中进行计算。 这个方法由 – (void)adjustTextDisplay调用,在为UITextView设置文本后,由外部类调用。 我不知道为什么将内容大小设置为屏幕的框架大小不会限制视图(如下所示),也不知道为什么此方法返回完整的string长度作为范围。

UIButton与图片和文字

我试图做一个button,基本上模仿在iphone的主屏幕上看到的button – 它有一个垂直放置在一些文本上方的图片,都是button的一部分,并突出显示时适当(暗淡,点击等)行为。 我已经尝试将图片或文本放入自己的框架中,但不起作用,因为在新框架中的任何一个都不会与button的其余部分变暗。 使用背景图像属性不起作用,因为我想要图像上方的图像 – 文本背后的区域应该是透明的。 我真的更喜欢编程解决scheme,而不是进入和编辑我的所有照片。

React Native:确定文本组件的行数

正如标题所说,我一直在试图find一种方法来确定文本组件后的文本组成部分的行数。 看看我下面的例子。 <Text> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi semper ut ipsum in ultrices. Vivamus fringilla lacinia odio in accumsan. Proin sit amet pellentesque tortor. Nam mollis sit amet ligula id convallis. Etiam in semper diam. Cras id elit consectetur, interdum ante id, tincidunt nisi. Integer non elit placerat, dignissim nibh at, […]

UILabel中心内容

这是我的代码: UILabel *myLabel; myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 300, 480)]; myLabel.lineBreakMode = UILineBreakModeWordWrap; myLabel.numberOfLines = 2; // 2 lines ; 0 – dynamical number of lines myLabel.text = @"Please select at least one image category!"; myLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size: 24.0]; myLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2); myLabel.backgroundColor = [UIColor clearColor]; [self.view addSubview:myLabel]; [myLabel release]; 我想知道是否可以将包装的文本居中放置在左侧:

NSLayoutManager:调用setLocation(_:forStartOfGlyphRange :)将禁用整个string中的字距?

我创build了简单的NSLayoutManager子类,允许为定义的子string设置自定义的布局位置: class PositionableLayoutManager: NSLayoutManager { var xOffsetsPerGlyphRange = [(NSRange, CGPoint)]() override func invalidateLayoutForCharacterRange(charRange: NSRange, actualCharacterRange actualCharRange: NSRangePointer) { super.invalidateLayoutForCharacterRange(charRange, actualCharacterRange: actualCharRange) for (range, offset) in xOffsetsPerGlyphRange { setLocation(offset, forStartOfGlyphRange: range) } } } 现在,我可以像这样定义任何字符范围的自定义位置: let glyphRange = layoutManager.glyphRangeForCharacterRange(charRange, actualCharacterRange: nil) layoutManager.xOffsetsPerGlyphRange.append((glyphRange, customPointLocation)) layoutManager.invalidateLayoutForCharacterRange(NSRange(location: 0, length: textStorage.length), actualCharacterRange: nil) 它工作正常,唯一的问题是,这种方式重新定位的任何字形范围都布置和绘制没有字间距。 这里是一个例子: 在绿框中使用我的PositionableLayoutManager绘制的文本没有字距,在粉红色的框中有与使用UILabel绘制的kering相同的文本进行比较。 我怎么能做同样的事情,但适当的字距?

iOS – 无法设置UILabel的文本

好,让我解释一下情况,我有两个视图控制器让我们先打电话给他们。 FirstViewController从UITableViewControllerinheritance SecondViewControllerinheritance自UIViewController SecondViewController的接口由Interface Builder构成,只包含一个标签和一个UIProgressView。 标签和UIProgressViewsockets都与正确的文件所有者(SecondViewController)连接。 一点点的代码,在FirstViewController: 以下方法由通知触发 – (void) addTransfer:(NSNotification *)notification{ NSLog(@"notification received"); NSDictionary *transferInfo = [notification userInfo]; // I think the problem is here aTransfer = [[DbTransfer alloc] initWithNibName:@"DbTransfer" bundle:nil]; // aTransfer.srcPath = [transferInfo objectForKey:@"srcPath"]; aTransfer.dstPath = [transferInfo objectForKey:@"dstPath"]; [aTransfer startTransfer]; [transfer addObject:aTransfer]; [self.tableView reloadData]; } 那些是tableView的dataSource方法 – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return […]

如何使NSStringDrawingContext缩小文本?

我试图使用iOS 6的属性stringAPI来计算文本的大小,并在必要时缩小字体大小。 但是,我不能像文档所说的那样工作。 NSString *string = @"This is a long text that doesn't shrink as it should"; NSStringDrawingContext *context = [NSStringDrawingContext new]; context.minimumScaleFactor = 0.5; UIFont *font = [UIFont fontWithName:@"SourceSansPro-Bold" size:32.f]; NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; paragraphStyle.lineBreakMode = NSLineBreakByClipping; NSDictionary *attributes = @{ NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle }; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:self.title attributes:attributes]; […]

ios:显示可变长度,多行文本的最佳方式

我正计划从文本文件加载多段落内容并在UI上显示它。 我将从几个文本文件中的一个文件加载,并且不会提前知道文本要多久。 我的第一个想法是在UIScrollView中使用UILabel。 但是,UILabel似乎不能根据其包含的行数进行扩展。 它是否正确? 如果UILabel不适合工作,应该使用什么? UIWebView的? UIWebView会为我处理好滚动吗?