iOS6、7、8、9新特性总汇和适配说明 (13)

CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace

                                          context:nil

                                          options:@{CIDetectorAccuracy: CIDetectorAccuracyHigh}];

 

NSDictionary *options = @{ CIDetectorSmile: @YES, CIDetectorEyeBlink: @YES };

 

NSArray *features = [detector featuresInImage:image.CIImage options:options];

 

for (CIFaceFeature *feature in features) {

    NSLog(@"Bounds: %@", NSStringFromCGRect(feature.bounds));

    

    if (feature.hasSmile) {

        NSLog(@"Nice smile!");

    } else {

        NSLog(@"Why so serious?");

    }

    if (feature.leftEyeClosed || feature.rightEyeClosed) {

        NSLog(@"Open your eyes!");

    }

}

 

[Format Time: 0.0055 seconds]

 

二十一、给UITextView增加了链接

现在在iOS添加你自己的Twitter账户更加简单了,现在你可以给一个NSAttributedString增加链接了,然后当它被点击的时候唤起一个定制的action。

首先,创建一个NSAttributedString然后增加给它增加一个NSLinkAttributeName 属性,见以下:

Crayon Syntax Highlighter v2.7.1

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"This is an example by @marcelofabri_"];

[attributedString addAttribute:NSLinkAttributeName

                         value:@"username://marcelofabri_"

                         range:[[attributedString string] rangeOfString:@"@marcelofabri_"]];

 

 

NSDictionary *linkAttributes = @{NSForegroundColorAttributeName: [UIColor greenColor],

                                 NSUnderlineColorAttributeName: [UIColor lightGrayColor],

                                 NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};

 

// assume that textView is a UITextView previously created (either by code or Interface Builder)

textView.linkTextAttributes = linkAttributes; // customizes the appearance of links

textView.attributedText = attributedString;

textView.delegate = self;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwgywp.html