iOS Development Basics-Fragmentation 43

Source: Internet
Author: User

1: Add gesture to left stroke, view and modify one of the coordinates, menu with hide and show

@property (strong,nonatomic) Uiswipegesturerecognizer *recognizer;
Self.recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (handleswipefrom:)];[ Self.recognizer setdirection: (Uiswipegesturerecognizerdirectionleft)]; [Self addGestureRecognizer:self.recognizer];
-(void) Handleswipefrom: ( Uiswipegesturerecognizer *) sender{if (sender.direction = = uiswipegesturerecognizerdirectionleft) {Self.rightBu        Tton.hidden=no;                        [Self.recognizer setdirection: (uiswipegesturerecognizerdirectionright)]; [Self.valuelabel mas_remakeconstraints:^ (Masconstraintmaker *make)            {Make.right.mas_equalTo (self.rightButton.left). With.offset (-5);            Make.centerY.mas_equalTo (self). With.offset (0);        Make.size.mas_equalTo (Cgsizemake (main_screen_width-180, 15));        }];    [Self.valuelabel layoutifneeded];        } else {self.rightbutton.hidden=yes;                [Self.recognizer setdirection: (Uiswipegesturerecognizerdirectionleft)]; [Self.valuelabel mas_remakeconstraints:^ (Masconstraintmaker *make)            {Make.right.mas_equalTo (self.right). With.offset (-15);            Make.centerY.mas_equalTo (self). With.offset (0); Make.size.mas_equalTo (Cgsizemake (main_screen_width-180, 15));        }];    [Self.valuelabel layoutifneeded]; }}

2: Property name begins with new resolution

@property (nonatomic,copy) NSString *new_passwd;

such as the above writing will be an error, you can replace

@property (Nonatomic,copy,getter = thenewpasswd) NSString *new_passwd;

3: Some Considerations for singleton classes

If the code inside the Allocwithzone is not written, using the following three types of created instances or three, does not conform to our use of the single case, of course, if you only for [Hltestobject sharedinstance] instantiation, is always satisfied , the initialized attribute object is placed in the sharedinstance, and if it is initialized inside the init, there will be a different scenario;

Hltestobject *objct1 = [Hltestobject sharedinstance]; NSLog (@ "%@", Objct1); Hltestobject *OBJC2 = [[Hltestobject alloc] init]; NSLog (@ "%@", OBJC2); Hltestobject *OBJC3 = [Hltestobject new]; NSLog (@ "%@", OBJC3);

Declaring attributes:

@property (assign, nonatomic) int height; @property (strong, nonatomic) NSObject *object; @property (Strong, Nonatomic ) Nsmutablearray *arraym;

Code content:

static hltestobject *instance = nil;+  (instancetype) sharedInstance{     static dispatch_once_t oncetoken;    dispatch_once (&onceToken, ^{         instance = [[[self class] alloc] init ];        instance.height = 10;         instance.object = [[NSObject alloc] init];         instance.arrayM = [[NSMutableArray alloc] init];     });     return instance;} +  (Instancetype) Allocwithzone: (struct _nszone *) zone{    static  Dispatch_once_t oncetoken;    dispatch_once (&onceToken, ^{         instance = [super allocwithzone: zone];    });     return instance;} -  (nsstring *) description{    nsstring *result = @ "";     result = [result stringbyappendingformat:@ "<%@: %p>", [Self class],  self];    result = [result stringbyappendingformat:@ " height  = %d, "Self.height];    result = [result stringbyappendingformat : @ " arraym = %p,",self.arraym];    result = [result  stringbyappendingformat:@ " object = %p,",self.object];    return  Result;}

4:uitextfield achieve a certain margin left empty

is through the Uitextfield Leftview to achieve, at the same time to set up Leftviewmode.

If you set the left and right margins, you need to add the Rightview function

-(void) settextfieldleftpadding: (Uitextfield *) TextField forwidth: (cgfloat) leftwidth{    cgrect frame = Textfield.frame;    Frame.size.width = Leftwidth;    UIView *leftview = [[UIView alloc] initwithframe:frame];    Textfield.leftviewmode = uitextfieldviewmodealways;    Textfield.leftview = Leftview;}

5:uicollectionview instances of asynchronous loading

-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *)    indexpath{static NSString * Cellidentifier = @ "Event"; Eventcollectionviewcell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:cellidentifier forIndexPath:    Indexpath];  Event *event = [events ObjectAtIndex:indexPath.item];    Replace "event" with whatever class your items entity Cell.eventTitle.text = [Event objectforkey:@ "title"];    Cell.eventImage.image = [Event objectforkey:@ "image"]; if (cell.eventImage.image = = nil) {NSString *imageurl = [[[Events ObjectAtIndex:indexPath.item] objectforkey:@ "Pho        To "] objectforkey:@" url "];        dispatch_queue_t IMAGEFETCHQ = dispatch_queue_create ("Image fetched", NULL);            Dispatch_async (IMAGEFETCHQ, ^{__weak uicollectionview *weakcollection;            NSData *imagedata = [NSData datawithcontentsofurl:[nsurl urlwithstring:imageurl]; UIImage *image = [UIImage imaGewithdata:imagedata]; if (image) {Dispatch_async (Dispatch_get_main_queue (), ^{[Event Setobject:im Age forkey:@ "image"];                Updating the model here [Weakcollection Reloaditemsatindexpaths:@[indexpath]];            });    }        }); } return cell;

6: How to get someone else app pictures

A: Open itunes on your Mac, click My app, find the app you just downloaded, right click on the Finder display

B: Press ENTER, modify the IPA file suffix of. zip, that is, the 6.3.22.ipa into 6.3.22.zip, here will be a prompt to ask if you are sure to modify the extension, click Use. zip

C: Directly double-click the zip to unzip, open the Unpacked folder, into the payload folder at this time, get the majority of resources. Including CSS, JS, pictures, MP3/4, fonts, xib and so on resources

D: Fetch resources from Assets.car (tool: http://pan.baidu.com/s/1kUVAT7p extract password: qrt5)

E: We in the above e-step in the folder where the search Assets.car can directly drag assets.car into it, yes, drag it into the line, click Start, when finished, click Output dir (IOS app All resources = Assets.car + . api File Decompression)

iOS Development Basics-Fragmentation 43

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.