小编Vid*_*and的帖子

如何在IOS中以编程方式创建TTTAttributedLabel对齐中心

我正在开发一个应用程序,其中我有一个字符串,其中包含前缀为#的标签.

我正在使用TTTAttribute标签添加指向给定字符串中具有前缀#的单词的链接.

当我添加到TTTAttribute标签的链接时.它成功添加,当点击它时,我能够在该字符串中获得具有前缀#的所选单词.

但我无法根据字符串长度对齐TTTAttribute标签的中心.

默认属性

attributedLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentCenter;

在应用链接时无法正常工作.我希望标签对齐中心的长度如下所示.

带有单个标签的标签

带有两个标签的标签

带有三个标签的标签

如果它是正常的TTTAttribute标签而没有应用链接,那么默认的对齐属性正确应用..

这是我用来添加链接的代码..

 - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSRange matchRange;
        NSString *tweet = @"#MYTWEET ,#tweet, #fashion #Share";

        NSScanner *scanner = [NSScanner scannerWithString:tweet];
        if (![scanner scanUpToString:@"#" intoString:nil]) {
            // there is no opening tag
        }
        NSString *result = nil;
        if (![scanner scanUpToString:@" " intoString:&result]) {
            // there is no closing tag
        }
        //@"theString is:%@",result);


        NSArray *words = [tweet componentsSeparatedByString:@" "];

      TTTAttributedLabel *attributedLabel=[[TTTAttributedLabel alloc]initWithFrame:CGRectMake(5, 200, 320, 40)];

      attributedLabel.textAlignment=NSTextAlignmentCenter;

        attributedLabel.text=tweet;

        words = [tweet componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@",0123456789`~!@$%^&*()_-+=.></?;:'* …
Run Code Online (Sandbox Code Playgroud)

objective-c ios tttattritubedlabel

6
推荐指数
2
解决办法
2947
查看次数

如何将手势限制在UIImageView的范围内?

Shalini命名标签在imageview上移动

我想限制黑色图像UIView在girlimageview bounds内移动.我不应该移动到girlimageview之外.

我的girlimageview是带框架的静态图像(5,0,310,320)

我正在使用UIGestureRecognizer在imageview上移动黑色图像.

我尝试使用以下代码UIPanGestureRecognizer来限制但无法限制它.

UIPanGestureRecognizer *panTagGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[panTagGesture setDelegate:self];
[blackanimateview addGestureRecognizer:panTagGesture];


 -(void) handlePan:(UIGestureRecognizer*)panGes{

        CGPoint point = [panGes locationInView:girlimageview];

        if (point.x < girlimageview.bounds.size.width) {

            CGRect newframe = CGRectMake(point.x, point.y, blackanimateview.frame.size.width, blackanimateview.frame.size.height);

            blackanimateview.frame = newframe;

        }
        if (point.y < girlimageview.bounds.size.height-160) {

            CGRect newframe = CGRectMake(point.x, point.y, blackanimateview.frame.size.width, blackanimateview.frame.size.height);

            blackanimateview.frame = newframe;  
        }
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

objective-c uiimageview uigesturerecognizer ios uipangesturerecognizer

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