Tag: uilabel

调整字体大小以适应多个UIButton,使它们都具有相同的字体大小

我有几个UIButton在一起,我想调整字体大小,以便它适合。 但是,每个button应使用相同的字体大小,以使它们看起来相同。 换句话说,我想要做的就是将所有button设置为相同的最小尺寸。 _button1.titleLabel.adjustsFontSizeToFitWidth = YES; _button2.titleLabel.adjustsFontSizeToFitWidth = YES; float minFont1 = _button1.titleLabel.font.pointSize; float minFont2 = _button2.titleLabel.font.pointSize; float fontSize = MIN(minFont1, minFont2); UIFont *tailoredFont = [_button1.titleLabel.font fontWithSize:fontSize]; _button1.titleLabel.font = tailoredFont; _button2.titleLabel.font = tailoredFont; 但是,这不起作用,因为titleLabel.font不反映字体的真实大小。

更改variables时更新UILabel文本

我有一个UIControl类,需要根据UIImageView位置进行一些计算,这个位置可以通过touchesBegan和touchesMoved(这个类中的所有东西)来移动。 比我想显示它作为我已经编程创build的UILabel。 class control : UIControl{ … let leftControl: UIImageView = UIImageView(image: UIImage(named: "left-control")) … func leftValue() -> String{ var leftValue : String = "0.0" leftValue = "\(leftControl.center.x)" return leftValue } } 和我的ViewController.swift class ViewController:UIViewController { let ctrl : Control = Control() let leftLabel : UILabel = UILabel(frame: CGRect(x: 40, y: 300, width: 150, height: […]

调整UILabel的大小并不完全正常

我正在调整表格的cell和UILabel 。 标签似乎被resize,但仍然在一行。 如何处理这个? 标签从故事板中设置为: Line Breaks: Word Wrap; Autoshrink: Fixed Font Size; Lines: 0 CGRect textRect = [cell.sampleLabel.text boundingRectWithSize:boundingSize options:NSStringDrawingUsesLineFragmentOrigin attributes: @{NSFontAttributeName:cell.sampleLabel.font} context:nil]; NSLog(@"textRect height: %f", textRect.size.height); cell.sampleLabel.frame = textRect; NSLog(@"label height: %f", cell.sampleLabel.frame.size.height); NSLog : 2013-12-20 11:04:41.623 DevCloud[16613:70b] textRect height: 223.091019 2013-12-20 11:04:41.624 DevCloud[16613:70b] label height: 224.000000 2013-12-20 11:04:41.626 DevCloud[16613:70b] textRect height: 223.091019 […]

如何在标签iOS中显示自定义Emojis Url链接

如何在标签中显示表情符号链接。 表情符号Unicode格式正确显示,但是当我们显示emojis url链接时,它不显示其显示相同的URL链接。 我使用这个代码来显示Emojis: – NSString * html = msCommentObj.mCommentText; NSAttributedString *attr = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)} documentAttributes:nil error:nil]; NSString *finalString = [attr string]; descriptionCommentsLbl.text = finalString;* 这是Emojis回应: – 是的。 https://mysponsers.com//img/emoticons/47.png https://mysponsers.com//img/emoticons/41.png

ios)添加不同的UILabel到UITableView中的每个单元格的objective-c问题

我将不同的文本添加到UITableView中的每个单元格。 但是当我这样做时,testing显示在除了第一个以外的每个单元格中。因此,如果在9到9之间的9个数字的数组显示在第二个单元格中,则分别在第三个单元格中显示2。 在第一个单元格中没有显示任何代码 // Customize the appearance of table view cells. – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell = [self getCellContentView:CellIdentifier]; } if (indexPath.row == 0) { NSLog(@"hi"); } //add another textfield […]

弯曲的文本代码修改

我有这个UILabel子类,创build一个文本在一个圆圈。 我有3个主要的问题: 在Swift for iOS中沿着圆形path绘制文本 我无法弄清楚,如何dynamic地将半径设置为一个圆弧,而不是一个完整的圆(现在是基于最小宽度/高度的半径)。 dynamic地将其重新变成平面文本。 (=实时设置半径0) 你不能label.sizeToFit() ,它label.sizeToFit()了一切。 所以我需要创build一些属性半径,可以在旅途中改变它。 var angle: CGFloat = 1.6 var clockwise: Bool = true var curveRadius:CGFloat = 32.0 override func draw(_ rect: CGRect) { centreArcPerpendicular() } func centreArcPerpendicular() { guard let context = UIGraphicsGetCurrentContext() else { return } let str = self.text ?? "" let size = self.bounds.size […]

iOS 6多行标签行距

UILabel中的行距有问题,我使用自定义字体,当我使用表情符号时,两行之间没有空格。 这显然看起来不太好。 所以我用这个代码行间距,但应用程序崩溃给出的错误 终止应用程序,由于未捕获exception“NSInternalInconsistencyException”,原因:'NSAttributedString无效的自动调整,它必须有一个单一的跨越段落风格(或没有)与一个无包装lineBreakMode。 if ([cell.label2 respondsToSelector:@selector(setAttributedText:)]) { UIFont *font =btMyriadProRegularWithSize14Pt; NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [paragraphStyle setLineSpacing: 22]; NSDictionary *attributes = @{ NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle }; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:chatMessage.msgString attributes:attributes]; [cell.label2 setAttributedText: attributedString]; } else { NSString * msg = [NSString stringWithFormat:@"%@: %@",chatMessage.from,chatMessage.msgString]; cell.label2.text = msg; }

将UIGestureRecognizer添加到UILabel的单个字母

现在我正在做一个iOS应用程序,我想通过简单的“删除字母”来实现删除UILabel中的字母的function。 我遇到的问题是将一个手势识别器添加到UILabel的单个字母中。 我已经search了这个网站,没有任何东西。只是要清楚,我不是添加一个手势识别器的整个标签,我只想要将其添加到单个字母。 任何帮助是极大的赞赏。 谢谢

关于使用MTLabel的设备旋转的麻烦

我必须使用MTLabel类的线间距的UILabel。 (引用的示例代码: https : //github.com/Tuszy/MTLabel ) 但存在一些问题。 我正在制作一个iPad应用程序。 这个应用程序可以旋转 – 风景或肖像。 我把UILabel和MTLable对象放在视图中而没有IB。 每当设备的方向改变时,文本的宽度也改变了。 这个结果不是我想要的。 我的代码: #import "MTLabel.h" 。 – (void)viewDidLoad { [super viewDidLoad]; MTLabel *TitleFont = [[MTLabel alloc] initWithFrame:CGRectMake(255, 60, 270, 60)]; [TitleFont setFont:[UIFont fontWithName:@"Arial" size:30.0]]; TitleFont.backgroundColor = [UIColor greenColor]; TitleFont.text = @"Happy! – 1"; TitleFont.autoresizingMask = UIViewAutoresizingFlexibleTopMargin& UIViewAutoresizingFlexibleLeftMargin&UIViewAutoresizingFlexibleRightMargin; TitleFont.autoresizingMask= UIViewAutoresizingFlexibleWidth; [self.view addSubview:TitleFont]; //———————- UILabel […]

iOS可点击的单词(UILabel或UIbutton的)

我想在我的应用程序中创build一个只读文本区域,允许用户点击任何单词,应用程序读取它。 然而,我有点困惑哪种方法是最好的。 我看到两个选项,使用UILabel,并创build一些方法来检测点击区域,然后将其匹配到该地区的单词,但这听起来很难实现。 另一方面,我可以使用一组单词来创buildUIbutton的列表。 任何意见和/或示例代码来帮助我将非常感激,谢谢贾森。 注意:每个视图上有大约30个字。 下面的解决scheme很好。 对于其他人想要使用这个,这四行将设置您的UIWebView有一个清晰的背景,并禁用任何滚动或反弹。 [[myWebView.subviews objectAtIndex:0] setScrollEnabled:NO]; [[myWebView.subviews objectAtIndex:0] setBounces:NO]; [myWebView setBackgroundColor:[UIColor clearColor]]; [myWebView setOpaque:NO]; 还有一些方便的CSS来阻止当用户按下并保持链接时打开的popup窗口。 *{-webkit-touch-callout:none; -webkit-user-select: none;}