iOS Development Basics-Fragmentation 10

Source: Internet
Author: User

1: How to increase the back effect when selecting a table cell column

if (cell = = nil) {        cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier: Cellidentifier];        Cell.backgroundcolor = [Uicolor clearcolor];        Cell.textLabel.font = [Uifont fontwithname:@ "Helveticaneue" size:18];        Cell.textLabel.textColor = [Uicolor whitecolor];        Cell.textLabel.highlightedTextColor = [Uicolor lightgraycolor];        UIView *sbg=[[uiview alloc] initWithFrame:cell.frame];        Sbg.backgroundcolor=[uicolor colorwithwhite:0.5 alpha:0.3];        Cell.selectedbackgroundview = SBG;    }

2: Modify the title bar text

Uicolor *CC = [Uicolor whitecolor];    Nsdictionary * dict = [nsdictionary dictionarywithobject:cc forkey:uitextattributetextcolor];    Self.navigationController.navigationBar.titleTextAttributes = Dict;

3: A scrolling start Page function code

#define Newfeaturecount 4@interface Hvwnewfeatureviewcontroller () <UIScrollViewDelegate> @property (nonatomic, Strong) Uipagecontrol *pagecontrol, @end @implementation hvwnewfeatureviewcontroller-(void) Viewdidload {[Super    Viewdidload];        Do any additional setup after loading the view.        Add ScrollView [self setupscrollview]; Add Pagecontrol [self Setuppagecontrol];} /** add ScrollView */-(void) Setupscrollview {//Create a scrollView uiscrollview *scrollview = [[Uiscrollview alloc] Ini    T];        Scrollview.frame = Self.view.bounds;  Add picture for (int i=0; i<newfeaturecount; i++) {//get picture NSString *featureimagename = [NSString        stringwithformat:@ "new_feature_%d", i+1];                Uiimageview *featureimageview = [[Uiimageview alloc] initwithimage:[uiimage Imagewithnamed:featureimagename]];        Set picture size position cgfloat featurewidth = self.view.width;        CGFloat featureheight = self.view.height; CGFloat FeaturEX = Featureimageview.width * i;        CGFloat Featurey = 0;                Featureimageview.frame = CGRectMake (Featurex, Featurey, Featurewidth, featureheight); If this is the last page, add the function button if (i = = (NewFeatureCount-1)) {//In order for the function button of the last page to take effect, the interactive function must be activated FEATUREIMAG                        eview.userinteractionenabled = YES;        [Self addfunctionbutton:featureimageview];    }//Add image to ScrollView [ScrollView Addsubview:featureimageview];    }//Set ScrollView function Property scrollview.userinteractionenabled = YES; scrollview.scrollenabled = YES; Support scrolling scrollview.contentsize = Cgsizemake (self.view.width * newfeaturecount, 0); Only need to scroll horizontally scrollview.pagingenabled = YES; Support paging scrollview.showshorizontalscrollindicator = NO; Hide horizontal scroll bar//set background color Scrollview.backgroundcolor = [Uicolor colorwithred:246/255.0 green:246/255.0 blue:246/255.0        ALPHA:1.0];        Set proxy scrollview.delegate = self; Add [Self.view ADDSUBview:scrollview];}  /** add Pagecontrol */-(void) Setuppagecontrol {//Pagecontrol cannot be added to ScrollView, or it will scroll with content Uipagecontrol *pagecontrol    = [[Uipagecontrol alloc] init];    Pagecontrol.pageindicatortintcolor = [Uicolor blackcolor];    Pagecontrol.currentpageindicatortintcolor = [Uicolor Redcolor];        Pagecontrol.numberofpages = Newfeaturecount;    Set Position Pagecontrol.centerx = self.view.width * 0.5;            Pagecontrol.centery = self.view.height * 0.9;    Self.pagecontrol = Pagecontrol; [Self.view Addsubview:pagecontrol];} #pragma mark-uiscrollviewdelegate/** ScrollView Scroll agent method, here Control page number indicator */-(void) Scrollviewdidscroll: (Uiscrollview *)  ScrollView {//round to make the picture scroll over the midline when changing the page number Self.pageControl.currentPage = Scrollview.contentoffset.x/scrollview.width + 0.5;} #pragma mark-last page Features/** Add function button */-(void) Addfunctionbutton: (Uiimageview *) ImageView {//Add "share" option button [self Addsha        Rebutton:imageview]; Add "Enter Weibo" button [self addenterweibobutton:imageview];} /** Share options byButton */-(void) Addsharebutton: (Uiimageview *) ImageView {//create button UIButton *sharebutton = [UIButton buttonwithtype:ui        Buttontypecustom];        [Sharebutton settitle:@ "Share to everyone" forstate:uicontrolstatenormal];    [Sharebutton setimage:[uiimage imagewithnamed:@ "New_feature_share_false"] forstate:uicontrolstatenormal];            [Sharebutton setimage:[uiimage imagewithnamed:@ "New_feature_share_true"] forstate:uicontrolstateselected];        [Sharebutton addtarget:self Action: @selector (sharebuttonclicked:) forcontrolevents:uicontroleventtouchupinside];        [Sharebutton Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];        Position size sharebutton.size = Cgsizemake (150, 50);    You must set the Size,center before you really are in the center, or you start from the top left corner!!!    Sharebutton.centerx = self.view.width * 0.5;    Sharebutton.centery = Self.view.height * 0.65;        Set inner Spacing sharebutton.titleedgeinsets = uiedgeinsetsmake (0, 10.0, 0, 0); Add [ImageView Addsubview:sharebutton];} /** Sharing Options Click event Method */-(VOID) sharebuttonclicked: (UIButton *) button {button.selected =!button.selected;} /** "Go to Weibo" button */-(void) Addenterweibobutton: (Uiimageview *) ImageView {//create button UIButton *enterbutton = [UIButton b    Uttonwithtype:uibuttontypecustom];    enterbutton.userinteractionenabled = YES; [Enterbutton setbackgroundimage:[uiimage imagewithnamed:@ "New_feature_finish_button"] forState:    UIControlStateNormal]; [Enterbutton setbackgroundimage:[uiimage imagewithnamed:@ "new_feature_finish_button_highlighted"] forState:    Uicontrolstatehighlighted];    [Enterbutton Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];        [Enterbutton settitle:@ "into Weibo" forstate:uicontrolstatenormal];    Position size enterbutton.size = enterButton.currentBackgroundImage.size;    Enterbutton.centerx = self.view.width * 0.5;        Enterbutton.centery = self.view.height * 0.8; Monitor Click [Enterbutton addtarget:self Action: @selector (enterweibobuttonclicked) forControlEvents: UicontroleventtouchupinsidE]; Add [ImageView Addsubview:enterbutton];}    /** "Go to Weibo" button click */-(void) enterweibobuttonclicked {UIWindow *window = [UIApplication Sharedapplication].keywindow; Window.rootviewcontroller = [[Hvwtabbarviewcontroller alloc] init];} @end

4: Add Delete Controller

Add controller: [Self addchildviewcontroller:toviewcontroller]; [Toviewcontroller didmovetoparentviewcontroller:self]; small instance:-(Ibaction) Btnaction: (ID) Sender {Ciderviewcontroller *    Cid=[[ciderviewcontroller alloc] init];    [Self addchildviewcontroller:cid];    CGRect frame=self.myview.bounds;    frame.origin.y=110;    frame.size.width=290;        frame.size.height=90;    Cid.view.frame=frame;    Cid.view.backgroundcolor=[uicolor Redcolor];    [Self.myview AddSubview:cid.view]; [CID didmovetoparentviewcontroller:self];} Delete Controller: 1. When we call the Removefromparentviewcontroller method to our view controller container, we must first call the method, and the parent parameter is the view controller that nil:[will delete Willmovetoparentviewcontroller:nil]; [Fromviewcontroller Willmovetoparentviewcontroller:nil]; [Fromviewcontroller Removefromparentviewcontroller]; Í some notes: about the use of the Willmovetoparentviewcontroller method and the Didmovetoparentviewcontroller Method 1. These two methods are called when the child tries to switch the controller! Called when the Transitionfromviewcontroller method is called. 2. When calling the Willmovetoparentviewcontroller method or the Didmovetoparentviewcontroller method, be aware that their arguments are used: When a child view controller is removed from the parent view controller, parThe ENT parameter is nil. That is: [the child attempting to remove the controller Willmovetoparentviewcontroller:nil]; When a child tries to join the parent view controller, the parent parameter is the parental view controller. That is: [The child view controller to be joined Didmovetoparentviewcontroller: Parent View controller];3. No need to call the child View Controller Willmovetoparentviewcontroller: Parent View Controller] method. Because when we call the [parent View controller Addchildviewcontroller: Child View Controller], it is already called by default. Only after the Transitionfromviewcontroller method is called, the Child View controller Didmovetoparentviewcontroller: Parent view controller];4. No calls to the child view Controller Didmovetoparentviewcontroller: Parent View Controller] method. Because when we call [child View Controller Removefromparentviewcontroller], it is already called by default. You only need to call before the Transitionfromviewcontroller method: [Child View Controller Willmovetoparentviewcontroller:nil]. Good article (http://www.cocoanetics.com/2012/04/containing-viewcontrollers/http://mobile.51cto.com/iphone-313146.htm)

5: Research on the Autoresizingmask attribute of UIView

There is a Autoresizingmask property in UIView, which corresponds to the value of an enumeration (as follows), which means that the position of the child control and the parent control is automatically adjusted to a height of width. Enum {   uiviewautoresizingnone                  = 0,   uiviewautoresizingflexibleleftmargin   = 1 << 0,   uiviewautoresizingflexiblewidth        = 1 < < 1,   uiviewautoresizingflexiblerightmargin  = 1 << 2,    uiviewautoresizingflexibletopmargin    = 1 << 3,    uiviewautoresizingflexibleheight       = 1 << 4,    Uiviewautoresizingflexiblebottommargin = 1 << 5}; Uiviewautoresizingnone is not automatically adjusted. Uiviewautoresizingflexibleleftmargin automatically adjusts the distance to the left of the superview, ensuring that the distance to the right of the Superview is constant. Uiviewautoresizingflexiblerightmargin automatically adjusts to the right distance from the Superview to ensure that the distance to the left of the Superview is constant. Uiviewautoresizingflexibletopmargin automatically adjusts the distance to the top of the Superview, guaranteeing the superThe distance from the bottom of the view does not change. Uiviewautoresizingflexiblebottommargin automatically adjusts the distance from the bottom of the Superview, that is, the distance from the top of the Superview is constant. Uiviewautoresizingflexiblewidth automatically adjusts its width to ensure that the distance to the left and right of the Superview is constant. Uiviewautoresizingflexibleheight automatically adjusts its height to ensure that the distance from the top and bottom of the Superview is constant. uiviewautoresizingflexibleleftmargin  | Uiviewautoresizingflexiblerightmargin automatically adjusts the distance to the left of the superview to ensure that the distance to the left and to the right is the same as the distance from the left and right. For example, the original distance is 20, 30, the adjusted distance should be 68,102, that is, 68/20=102/30. Other combinations are similar. Example: cgrect frame = [[UIScreen mainscreen] applicationframe]; UIView *view = [[UIView alloc] Initwithframe:frame];view.autoresizingmask = Uiviewautoresizingflexiblewidth | Uiviewautoresizingflexibleheight;

6: System-provided dispatch method

To make it easy to use GCD, Apple provides some ways for us to put blocks on the main thread or background thread, or to postpone execution. Examples of use are as follows: 1//   background Execution:  2  dispatch_async (Dispatch_get_global_queue (0, 0),  ^{&nbsp    ; 3       // something  4  });  5  //  main thread execution: &nbsp    ; 6  dispatch_async (Dispatch_get_main_queue (), ^{  7       // som ething  8  });  9  //  One-time execution:   static dispatch_once_t on cetoken;   dispatch_once (&onceToken, ^{       // c ode to be executed once   });   //  delay 2 Second execution:  15 & nbsp;double delayinseconds = 2.0;   dispatch_time_t popTime =     Dispatch_time (dispatch_time_now, delayinseconds * nsec_per_sec);  17 dispatch_after (Poptime, dispatch_get_main_queue (),  ^ (void) {        // code to be executed on the main queue after delay    });  dispatch_queue_t can also define itself, if you want to customize the queue, you can use the Dispatch_queue_create method, as shown in the following example: 1 Dispatch_queu E_t urls_queue = dispatch_queue_create ("blog.devtang.com",  null);  2 Dispatch_async ( urls_queue, ^{  3      // your code  4});  5 dis Patch_release (Urls_queue);  In addition, GCD has some advanced usage, such as having 2 threads in the background executing in parallel, and then summarizing the execution results after 2 threads have finished. This can be achieved with Dispatch_group, Dispatch_group_async and Dispatch_group_notify, as shown in the following example: 1 Dispatch_group_t group =&nbs P;dispatch_group_create ();  2 Dispatch_group_async (Group, dispatch_get_global_queue (0,0),  ^{   3       //  thread of parallel execution   4  });  5    dispatch_group_async (Group, dispatch_get_global_queue (0,0), ^{  6     & nbsp; //  parallel Execution Thread two   7  });  8  dispatch_group_notify (Group, dispatch_get_glo Bal_queue (0,0), ^{  9       //  Summary results   &NBSP;}); 

iOS Development Basics-Fragmentation 10

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.