Basic knowledge of IOS development-fragment 30, basic knowledge of ios-Fragment

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 30, basic knowledge of ios-Fragment

1: knowledge points of ALAssetsLibrary in ios album operations

The a ALAssetsLibrary instance provides us with the function of getting pictures and videos in an album (photo app. In ios8 photos framework, ALAssetsLibrary is replaced.

When using ALAssetsLibrary, We need to declare its instance.

ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

 

B. Obtain the album ALAssetsGroup iteratively:

- (void)enumerateGroupsWithTypes:(ALAssetsGroupType)types                      usingBlock:(ALAssetsLibraryGroupsEnumerationResultsBlock)enumerationBlock                    failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock

ALASSetsGroupType type:

ALAssetsGroupLibrary: album content from iTunes (for example, self-contained sunflower photos ).

ALAssetsGroupAlbum: A photo generated by the device itself or synchronized from iTunes, but not included in the photo stream and sharing stream. (For example, images saved from various software)

Album generated by ALAssetsGroupEvent camera interface event

ALAssetsGroupFaces face album (Unclear)

ALAssetsGroupSavedPhotos camera film photo

ALAssetsGroupPhotoStream photo stream

ALAssetsGroupAll except the content above ALAssetsGroupLibrary.


Example: ALAssetsLibraryGroupsEnumerationResultsBlock

  ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {    ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos];        [group setAssetsFilter:onlyPhotosFilter];        if ([group numberOfAssets] > 0)        {            [self.imageGroup addObject:group];        }        else        {            [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];        }    };

The above is the block for iteration of AlAssetsGroup. Each iteration stores the corresponding AlAssetsGroup in a variable array. Some attributes in AlAssetsGroup indicate the characteristics of the album. For example:
Thumbnail of A posterImage album

Number of photos in numberOfAssets album

 

C: Asset attributes

-ValueForProperty:
1. ALAssetPropertyType resource type (photo, video)
2. ALAssetPropertyLocation: geographical location of the resource (null is returned if there is no location information)
3. ALAssetPropertyDuation playback duration (the photo returns ALErorInvalidProperty)
4. ALAssetPropertyOrientation direction (there are eight directions in total. For details, see ALAssetOrientation)
5. ALAssetPropertyDate shooting time (including year and day, hour, and second)
6. ALAssetPropertyRepresentations description (printed and read, only the name with a suffix)
7. ALAssetPropertyURLs (a dictionary is returned, and the key values are file names and file URLs respectively)
8. url of the ALAssetPropertyAssetURL file)
Editable property (indicates whether the resource can be edited, read-only attribute)
OriginalAsset property (original resource. If the modified resource is not saved, the original resource is nil)

    for (ALAsset *asset in assets) {       NSURL *assetURL= [asset valueForProperty:ALAssetPropertyAssetURL];    }

Accessing Representations
-DefaultRepresentation
-Representationforti:
-Thumbnail (thumbnail of a small square)
-AspectRatioThumbnail (thumbnail based on the ratio of original resource length to width)

Another small instance:

UIImage * ni = [UIImage imageNamed: @ "new.png"]; // modify the image resource content in the specified path and replace the original content with [asset setImageData: UIImageJPEGRepresentation (ni, 1.0) metadata: nil completionBlock: ^ (NSURL * assetURL, NSError * error) {NSLog (@ "new: % @", assetURL) ;}]; // Based on the specified image content, regenerate a new image [asset metadata: UIImageJPEGRepresentation (ni, 1.0) metadata: nil completionBlock: ^ (NSURL * assetURL, NSError * error) {NSLog (@ "new: % @", assetURL) ;}]; // obtain the detailed resource information of the resource image. ALAssetRepresentation * representation = [asset defaultRepresentation]; // obtain the length and width of the resource image CGSize dimension = [representation dimensions]; // obtain the high-definition image of the resource image [representation fullResolutionImage]; // obtain the full-screen image of the resource image [representation fullScreenImage]; // obtain the resource image name NSString * filename = [representation filename]; NSLog (@ "filename: % @", filename); // scale multiple [representation scale]; // image resource capacity [representation size]; // original image resource data [representation metadata]; // Rotation Direction [representation orientation]; // resource image url, this address is the same as the url obtained by ALAsset through ALAssetPropertyAssetURL. NSURL * url = [representation url]; NSLog (@ "url: % @", url ); // resource image (UI), the unique identifier NSLog (@ "UI: % @", [representation uti]);

 

2: Use Attribute (several pieces of code)

AddAttribute can add different attributes. Some attribute values must be set in NSMutableParagraphStyle. For example, NSParagraphStyleAttributeName In the first code below. Some attributes can be set directly, for example, NSForegroundColorAttributeName.

            NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];            [style setLineSpacing:5];            [muttext addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, muttext.length)];            [muttext addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, muttext.length)];            _myLabel.attributedText = muttext;
NSMutableParagraphStyle * paragraph = [[NSMutableParagraphStyle alloc] init]; paragraph. alignment = NSTextAlignmentCenter; // center NSDictionary * attrs =@{ NSFontAttributeName: [UIFont fontWithName: @ "AmericanTypewriter" size: 30], // text color font size: [UIColor redColor], // text color NSParagraphStyleAttributeName: paragraph, // paragraph Format // NSBackgroundColorAttributeName: [UIColor blueColor], // NSStrokeWidthAttributeName: @ 3, // stroke width NSStrokeColorAttributeName: [UIColor greenColor], // sets the stroke color and works with NSStrokeWidthAttributeName. If NSForegroundColorAttributeName is set, it becomes invalid. // mask: @ 1, // strikethrough. The number indicates the line width. NSUnderlineStyleAttributeName: @ (NSUnderlineStyleSingle), // underline. The value is of an enumeration type. You can try it separately };
-(Optional *) setTitle {NSMutableAttributedString * title = [[NSMutableAttributedString alloc] initWithString: @ ""]; [title addAttribute: NSForegroundColorAttributeName value: COLOR_NAV_TITLE range: NSMakeRange, title. length)]; [title addattriename: NSFontAttributeName value: SYSTEMFONT (18) range: NSMakeRange (0, title. length)]; return title ;}
1. if the textView content is set to the row spacing, run the following code: // textview to change the row spacing of the font NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle. lineSpacing = 10; // line spacing of the font NSDictionary * attributes = @ {NSFontAttributeName: [UIFont systemFontOfSize: 15], NSParagraphStyleAttributeName: paragraphStyle}; textView. attributedText = [[NSAttributedString alloc] initWithString: @ "Enter your content" attributes: attributes]; 2. if you want to dynamically change the input content according to the set line spacing, you need to put the above Code in the delegate method of textView-(void) textViewDidChange :( UITextView *) textView {// textview changes the row spacing of the font NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle. lineSpacing = 20; // line spacing of the font NSDictionary * attributes = @ {NSFontAttributeName: [UIFont systemFontOfSize: 15], NSParagraphStyleAttributeName: paragraphStyle}; textView. attributedText = [[NSAttributedString alloc] initWithString: textView. text attributes: attributes];}

 

3: the keyboard of the Chinese input method has Lenovo and recommendation functions, which may result in some unsatisfactory text content length and cross-border

*** Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds'

The processing method is as follows (TextView. markedTextRange = nil)

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{    if (textView.text.length >= self.textLengthLimit && text.length > range.length) {        return NO;    }        return YES;}- (void)textViewDidChange:(UITextView *)textView{    self.placeholder.hidden = (self.textView.text.length > 0);        if (textView.markedTextRange == nil && self.textLengthLimit > 0 && self.text.length > self.textLengthLimit) {        textView.text = [textView.text substringToIndex:self.textLengthLimit];    }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.