Tag: uilabel

向UILabel的一部分添加轻击手势

我有一个NSAttributedString像这样: NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"testing it out @clickhere"]; NSInteger length = str.length; [str addAttribute:NSForegroundColorAttributeName value:[UIColor bestTextColor] range:NSMakeRange(0,length)]; NSMutableAttributedString被设置为一个UILabel像这样: label.attributedText = str; 如何在另一个视图控制器上为上面的string中的“@clickhere”做一个点击手势(或点击)? 谢谢!

UITapGestureRecognizer initWithTarget:动作:方法采取参数?

我正在使用UITapGestureRecognizer因为我使用UIScrollView作为我的UILabel的容器。 基本上我试图用参数使用一个动作方法,所以我可以例如发送myLabel.tag值的行动方法知道要采取什么行动取决于已经触发了一个水龙头UILabel。 其中一种方法是使用与UILabel一样多的操作方法,但这不是代码方式的“漂亮”。 我想实现的只是一个具有switch语句的操作方法。 这是可能的,还是我必须这样做(叹气): UITapGestureRecognizer *myLabel1Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myLabel1Tap)]; [myLabel1Tap addGestureRecognizer:myLabel1Tap]; UITapGestureRecognizer *myLabel2Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myLabel2Tap)]; [myLabel1Tap addGestureRecognizer:myLabel2Tap]; UITapGestureRecognizer *myLabelNTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myLabelNTap)]; [myLabel1Tap addGestureRecognizer:myLabelNTap]; – (void)myLabel1Tap { // Perform action } – (void)myLabel2Tap { // Perform action } – (void)myLabelNTap { // Perform action }

顶部alignmentUILabel中不同大小的文本

如何在UILabel中alignment不同大小的文本? 一个例子是在价格横幅上调整较小尺寸的美元数量和较大尺寸的美元数量。 iOS6中的UILabel支持NSAttributedString ,它允许我在同一个UILabel中有不同大小的文本。 但是,它似乎没有用于顶部alignment文本的属性。 有什么select来实现这个? 在我看来,提供一个自定义的绘图逻辑来完成基于自定义属性string键的顶部alignment可能是最好的,但我不知道如何去做。

缩放字体大小以垂直放入UILabel

我想要一个标准的UILabel并增加字体大小,以便填充垂直空间。 从这个问题的被接受的答案中获得灵感,我用这个drawRect实现在UILabel上定义了一个子类: – (void)drawRect:(CGRect)rect { // Size required to render string CGSize size = [self.text sizeWithFont:self.font]; // For current font point size, calculate points per pixel float pointsPerPixel = size.height / self.font.pointSize; // Scale up point size for the height of the label float desiredPointSize = rect.size.height * pointsPerPixel; // Create and assign new UIFont […]

使字体与UILabel(通过自动布局resize)一起增长 – 如何在Interface Builder中实现?

在一个简单的iPhone应用程序中,通过viewDidLoad中的以下代码显示一个字母拼贴(带有图像和2个标签的自定义UIView ): DraggedTile *tile = [[[NSBundle mainBundle] loadNibNamed:@"DraggedTile" owner:self options:nil] firstObject]; tile.frame = CGRectMake(10 + arc4random_uniform(100), 10 + arc4random_uniform(100), kWidth, kHeight); [self.view addSubview:tile]; 这工作正常,但我想使字母瓷砖生长 – 当我提供更大的宽度和高度参数的CGRectMake 。 所以在Xcode 5.1界面生成器中,我打开DraggedTile.xib并启用“自动布局”。 然后,对于image和letter我将限制添加到父级的左侧,顶部,右侧,底部边缘。 对于letter标签,我还将“Lines”设置为0,将“Content Compression Resistance Priority”设置为1000(这里是全屏幕1和全屏幕2 ): 然后我修改代码使用更大的宽度和高度: tile.frame = CGRectMake(10 + arc4random_uniform(100), 10 + arc4random_uniform(100), 2 * kWidth, 2 * kHeight); 结果如下: 背景image和letter标签似乎都是按照预期成长的。 然而,标签的字体大小还没有增长。 我周围search,我认为我需要像tile.letter.adjustsFontSizeToFitWidth = […]

iOS 8 – 在Interface Builder中更改UILabel上的字符间距

有无论如何改变使用Interface Builder的UILabel文本的字符间距(轨道)? 如果没有,是否有办法以编程方式在已经使用属性文本创build的现有UILabel上进行编辑?

向故事板中的UILabel归因string添加下划线失败

从故事板中select相关的UILabel 然后在属性检查器>标签> [我select]归属 同样在属性检查器>标签>文本> [我select的内容] 然后我点击字体图标并select下划线 基本上,我从popup的字体窗口中select的任何更改都不会生效。 有没有人成功添加故事板下划线? 注:我已经知道如何在代码中做到这一点。 我想避免添加代码。

在标题中有两行文本的UIButton(numberOfLines = 2)

我试图做一个UIButton在其titleLabel中有两行文字。 这是我正在使用的代码: UIButton *titleButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)]; titleButton.titleLabel.font = [UIFont boldSystemFontOfSize:24.0]; [titleButton setTitle:@"This text is very long and should get truncated at the end of the second line" forState:UIControlStateNormal]; titleButton.titleLabel.lineBreakMode = UILineBreakModeTailTruncation; titleButton.titleLabel.numberOfLines = 2; [self addSubview:titleButton]; 当我尝试这个时,文本只出现在一行上。 看来在UIButton.titleLabel实现多行文本的唯一方法是设置numberOfLines=0并使用UILineBreakModeWordWrap 。 但是这并不能保证文本恰好是两行。 然而,使用一个普通的UILabel是行不通的: UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)]; […]

在Objective-C中如何等待

我想在2秒后更改我的UILabel的文本。 我尝试将我的UILabel的文本设置为“一个文本” ,并使用sleep(2) ,最后将文本更改为“另一个文本” 。 但sleep(2)只冻结了应用程序,并设置了“另一个文本” ,而不显示“文本” 2秒。 如何显示“文本” 2秒钟,然后显示“另一个文本” ?

UILabel文本iphone中的问题

我有一个标签,其中有一个dynamic的string数据,例如:“我是Mohit”。我只想做粗体的“上午”。这是可能的iPhone? 如果是的请给我build议。感谢提前:)