Sagit.Framework For IOS automatic layout tutorial: 13. Uiimage, uiimageview image compression, (long press) save, zoom, (list) enlarge browse, generate captcha.

Time:2020-10-21

preface:

This article introduces the common functions and usages of uiimage and uiimageview elements.

1. Uiimage special usage: picture compression, picture save album, picture zoom, return picture data.

Basic definition:

@interface UIImage(ST)
//! there is a name for each UI extension
@property (nonatomic,copy) NSString* name;
typedef void (^AfterImageSave)(NSError *err);
@property (nonatomic,copy) AfterImageSave afterImageSaveBlock;
//! get the compressed byte data of the picture. The current picture will not be changed
-(NSData*)compress:(NSInteger)maxKb;
-(void)save:(AfterImageSave)afterSave;
//! detect proportional scaling of maximum width and height
-(UIImage *)reSize:(CGSize)maxSize;
-(NSData*)data;
@end

2. Uiimageview special usage: long press to save events, save album events, fillet, zoom, select image library (single choice), web address to load pictures.

Basic definition

@interface UIImageView(ST)

typedef void (^OnPick)(NSData *data,UIImagePickerController *picker,NSDictionary *info);
//typedef void (^AfterSetImageUrl)(UIImageView* img);
//! prompt users to save pictures on time
-(UIImageView*)longPressSave:(BOOL)yesNo;
//! execute save picture event
-(UIImageView*)save;
//! set whether the picture is rounded
-(UIImageView*)corner:(BOOL)yesNo;
//! get the address of the picture
-(NSString*)url;
//! set a network address for the picture (it will be compressed if it exceeds 256K by default)
-(UIImageView*)url:(NSString*)url;
//! set a network address for the picture (it will be compressed if it exceeds 256K by default)afterSet为设置后的回调函数
//-(UIImageView *)url:(NSString *)url after:(AfterSetImageUrl)block;
//! set a network address for the picture (it will be compressed if it exceeds 256K by default)default:设置一张默认图片
-(UIImageView *)url:(NSString *)url default:(id)imgOrName;
//! set a network address for the picture, and maxkb should be compressed when it is larger than the specified size (set to 0 to not compress)
//-(UIImageView *)url:(NSString *)url maxKb:(NSInteger)compress;
//! set a network address for the picture (it will be compressed if it exceeds 256K by default) maxKb 指定超过大小时压缩显示(设置为0不压缩) default:设置一张默认图片
-(UIImageView *)url:(NSString *)url  default:(id)imgOrName maxKb:(NSInteger)compress;
//! set a network address for the picture (it will be compressed if it exceeds 256K by default) maxKb 指定超过大小时压缩显示(设置为0不压缩) default:设置一张默认图片 afterSet为设置后的回调函数
//-(UIImageView *)url:(NSString *)url maxKb:(NSInteger)compress default:(id)imgOrName after:(AfterSetImageUrl)block;
//! picture selection edit: whether crop box appears
-(UIImageView*)pick:(OnPick)pick edit:(BOOL)yesNo;
//! picture selection edit: whether crop box appears maxKb:指定压缩的大小
-(UIImageView*)pick:(OnPick)pick edit:(BOOL)yesNo maxKb:(NSInteger)maxKb;

//! compress the picture to the specified width and height. The current picture will be changed
-(UIImageView*)reSize:(CGSize)maxSize;

New features:

#Pragma mark view large image, (remove the third party picture to view)
//! double click to zoom in
-(void)zoom;
-(UIImageView *)zoom:(BOOL)yesNo;
//Click to view
-(void)show;
-(UIImageView *)show:(BOOL)yesNo;
+(void)show:(NSInteger)startIndex images:(id)imgOrNameOrArray,...NS_REQUIRES_NIL_TERMINATION;

3. Examples of use

This is the implementation function of the internal pop-up picture, which just uses a lot of image functions. For example, it can also be used:

+(void)show:(NSInteger)startIndex images:(id)imgOrNameOrArray, ...
{
    if(imgOrNameOrArray==nil){return;}
    [Sagit.MsgBox dialog:^(UIView *winView) {
        [[[winView addScrollView:nil direction:X]  addImages:imgOrNameOrArray, nil]block:^(UIScrollView* scrollView) {
            [scrollView setPagerIndex:startIndex];
            [[scrollView showPager:YES] backgroundColor:ColorBlack];
            scrollView.onPrePager = ^(UIScrollView *scrollView) {

            };
            scrollView.onNextPager = ^(UIScrollView *scrollView) {
                
            };
            for (int i=0; i

Example 2:

[imgView onClick:^(UIView *view)
            {
                NSMutableArray *array=[NSMutableArray new];
                for (PersonalPhoto *item in photos) {
                    [array addObject:item.BigPhotoPath];
                }
                [UIImageView show:i images:array, nil];
            }];

effect:

4. Generate verification code: [background color or font color can be specified]

definition:

#Pragma mark local verification code
-(NSString*)VerifyCode;
//! generates the specified length captcha (random background color).
-(UIImageView*)VerifyCode:(NSInteger)length;
//! generate verification code of specified length (specify background color, random font color).
-(UIImageView*)VerifyCode:(NSInteger)length fixBgColor:(UIColor*)fixBgColor;
//! generate verification code of specified length (specify background color, specify font color).
-(UIImageView *)VerifyCode:(NSInteger)length fixBgColor:(UIColor *)fixBgColor fixFontColor:(UIColor *)fixFontColor;

Example code:

[[[[sagit addImageView:@“imgCode”] width:300 height:100] layerCornerRadius:30] .asImageView VerifyCode:4] toCenter];

Picture:

 

Get verification code:

NSString *code=STImageView("imgCode").VerifyCode;

 

Recommended Today

Layout of angular material (2): layout container

Layout container Layout and container Using thelayoutDirective to specify the layout direction for its child elements: arrange horizontally(layout=”row”)Or vertically(layout=”column”)。 Note that if thelayoutInstruction has no value, thenrowIs the default layout direction. row: items arranged horizontally.max-height = 100%andmax-widthIs the width of the item in the container. column: items arranged vertically.max-width = 100%andmax-heightIs the height of the […]