相关疑难解决方法(0)

是否可以在 UILabel / UITextView 中添加 UIButton?

这是一个有趣的场景。我从服务器发送了以下文本:

我通过#option#上学

在 iOS 应用程序中,我必须将其转换为:

我通过[UIButton]上学

我们面临的挑战是测量在前文(“我去上学”)的长度,以设置的位置(origin的)UIButton。当UILabel有多行,多次出现时UIButton,问题会更严重,例如:

我通过#option#上学。Lorem ipsum dolor 坐 amet,consectetur adipiscing 精英。Phasellus fringilla、massa ut pharetra ultricies、elit nunc accumsan libero、ut elementum est justo sed lacus。Proin mitellus, suscipit in magna a, auctor laoreet eros. #option# Quisque rhoncus ac mauris ac interdum。Etiam a odio augue。Mauris porttitor purus ac maximus faucibus。Suspendisse velit felis、varius lobortis turpis venenatis、tempor placerat magna。semper justo 中的整数,ut pretium nunc。Aliquam laoreet vehicula finibus。#选项#

以下是我能想到的一些解决方案:

方法一

NSString * testText = …
Run Code Online (Sandbox Code Playgroud)

objective-c ios

5
推荐指数
1
解决办法
2758
查看次数

是否可以将超链接添加到UIAlertController?

技术:Objective-C,xCode 7

@property (nonatomic, copy) NSString *notes;
@synthesize notes;

example.notes = @"Click <a href='http://www.google.com'>here</a>";

NSString *msg = [@"" stringByAppendingFormat:@"%@", myAnnotation.notes];

UIAlertController *alertViewController = [UIAlertController alertControllerWithTitle: @"Title of Alert Box" message: msg preferredStyle: UIAlertControllerStyleAlert];
[alertViewController addAction: [UIAlertAction actionWithTitle: @"Close" style: UIAlertActionStyleCancel handler: nil]];
[self presentViewController: alertViewController animated: YES completion: nil];
Run Code Online (Sandbox Code Playgroud)

试图使链接出现在警报框中,但没有运气。只是输出为纯文本。

这有可能吗?如果是这样,使用上面的示例,您将如何实现它?

objective-c ios uialertcontroller

4
推荐指数
1
解决办法
5252
查看次数

在NSTextFieldCell中创建一个可点击的URL

这个问题分为两部分:

(1)如何检测给定文本中的URL?

(2)如何在文本字段单元格(在表格视图中)中单击文本的一部分?我想要点击URL,在默认的Web浏览器中打开.

cocoa objective-c

3
推荐指数
1
解决办法
3740
查看次数

如何使可点击的 NSAttributedString 移动到另一个 ViewController Swift

我正在开发一个简单的应用程序并以编程方式添加NSAttributedString. 我真的很困惑如何将礼物viewcontroller转移到另一个viewcontroller

这不是重复的问题,因为我的问题是如何移动到视图控制器和重复问题如何在单击时打开链接 如何在 NSAttributedString 中创建可点击的链接?.

截屏

截屏

在上图中显示了三个,NSAttributedString第一个是dhiman.sham1gmail.com,第二个是has started following,第三个Sham。尝试单击时Sham不执行任何操作。我想在单击时将此控制器移动到另一个控制器Sham

这是我的代码:

@IBOutlet weak var descriptionLbl: UILabel!

override func updateWithModel(_ model: AnyObject) {
 self.descriptionLbl.attributedText = self.followingGetTextFromType(data: (model as? FollowingNotificationData)!)
}

func followingGetTextFromType(data:FollowingNotificationData) -> NSMutableAttributedString{
  var attributedString = NSMutableAttributedString()
  attributedString = NSMutableAttributedString(string:(data.detailsNoti?.fullName)!, attributes: strres)
  let startedfollowing = NSMutableAttributedString(string:" has started following ", attributes: attrs)
  attributedString.append(startedfollowing)
  var discription = NSMutableAttributedString()
  if data.fullName == ""{ …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller nsattributedstring ios swift nsattributedstringkey

2
推荐指数
1
解决办法
1985
查看次数

添加到NSString iOS的超链接

我有一个简单的NSString,例如:

NSString*text = @"Stackoverflow太神奇了!"

我想把Stackoverflow这个词变成指向https://stackoverflow.com/的超链接,并且仍然可以将字符串作为变量输出.这可能吗?

objective-c hyperlink nsstring

1
推荐指数
1
解决办法
3054
查看次数