<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      開發細節(二)

      1. 利用Auto Layout整體排列控件

      下面的代碼演示了一個控件如何在其父容器中垂直水平居中:

      UIView *box = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 150)];
      box.backgroundColor = [UIColor grayColor];
      [self.view addSubview:box];
      
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      [button setTitle:@"a button" forState:UIControlStateNormal];
      [button sizeToFit];
      button.translatesAutoresizingMaskIntoConstraints = NO;
      [box addSubview:button];
      
      NSMutableArray *array = [[NSMutableArray alloc] init];
      
      [array addObjectsFromArray:[NSLayoutConstraint
                                  constraintsWithVisualFormat:@"V:[box]-(<=1)-[button]"
                                  options:NSLayoutFormatAlignAllCenterX
                                  metrics:nil
                                  views:NSDictionaryOfVariableBindings(box,button)]];
      
      [array addObjectsFromArray:[NSLayoutConstraint
                                  constraintsWithVisualFormat:@"H:[box]-(<=1)-[button]"
                                  options:NSLayoutFormatAlignAllCenterY
                                  metrics:nil
                                  views:NSDictionaryOfVariableBindings(box,button)]];
      
      [box addConstraints:array];

      下面的代碼演示了多個控件其父容器中水平左對齊,垂直居中:

      UIView *box = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 150)];
      box.backgroundColor = [UIColor grayColor];
      [self.view addSubview:box];
          
      UILabel *label = [[UILabel alloc] init];
      label.text = @"a label";
      [label sizeToFit];
      label.backgroundColor = [UIColor redColor];
      label.translatesAutoresizingMaskIntoConstraints = NO;
      [box addSubview:label];
      
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      [button setTitle:@"a button" forState:UIControlStateNormal];
      [button sizeToFit];
      button.translatesAutoresizingMaskIntoConstraints = NO;
      [box addSubview:button];
      
      NSMutableArray *array = [[NSMutableArray alloc] init];
      
      [array addObjectsFromArray:[NSLayoutConstraint
                                  constraintsWithVisualFormat:@"V:|-[button]-|"
                                  options:NSLayoutFormatAlignAllLeft
                                  metrics:nil
                                  views:NSDictionaryOfVariableBindings(button)]];
      
      [array addObjectsFromArray:[NSLayoutConstraint
                                  constraintsWithVisualFormat:@"|-15-[myLabel]-5-[myButton]"
                                  options:NSLayoutFormatAlignAllCenterY
                                  metrics:nil
                                  views:@{@"myLabel":label, @"myButton":button}]];
      
      [box addConstraints:array];

      2. ScrollView利用Auto Layout管理控件

      3. IB_DESIGNABLE,IBInspectable配合XIB實現自定義控件

      #import <UIKit/UIKit.h>
      
      @interface MyTempView : UIView
      
      @property (weak, nonatomic) IBOutlet UIView *contentView;
      @property (weak, nonatomic) IBOutlet UILabel *myLabel;
      
      @end
      MyTempView.h
      #import "MyTempView.h"
      
      IB_DESIGNABLE
      @interface MyTempView ()
      
      @property (nonatomic) IBInspectable NSString *myText;
      @end
      
      @implementation MyTempView
      
      - (void)setMyText:(NSString *)myText {
          self.myLabel.text = myText;
      }
      
      - (instancetype)initWithFrame:(CGRect)frame {
          self = [super initWithFrame:frame];
          if (self) {
              [self commonSetup];
          }
          return self;
      }
      
      - (instancetype)initWithCoder:(NSCoder *)aDecoder {
          self = [super initWithCoder:aDecoder];
          if (self) {
              [self commonSetup];
          }
          return self;
      }
      
      - (UIView *)loadViewFromNib {
          NSBundle *bundle = [NSBundle bundleForClass:[self class]];
          
          //xib文件名與類文件名不同
      //    UIView *view = [[bundle loadNibNamed:@"abc" owner:self options:nil] firstObject];
          
          //xib文件名與類文件名相同
          UIView *view = [[bundle loadNibNamed:NSStringFromClass([self class])  owner:self options:nil] firstObject];
          
          return view;
      }
      
      - (void)commonSetup {
          UIView *nibView = [self loadViewFromNib];
          nibView.frame = self.bounds;
          // the autoresizingMask will be converted to constraints, the frame will match the parent view frame
          nibView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
          // Adding nibView on the top of our view
          [self addSubview:nibView];
      }
      @end
      MyTempView.m
      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
          <dependencies>
              <deployment identifier="iOS"/>
              <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
          </dependencies>
          <objects>
              <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MyTempView">
                  <connections>
                      <outlet property="contentView" destination="iN0-l3-epB" id="a2U-Rp-jYq"/>
                      <outlet property="myLabel" destination="IIE-8B-dDU" id="mM8-Li-TQ0"/>
                  </connections>
              </placeholder>
              <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
              <view contentMode="scaleToFill" id="iN0-l3-epB">
                  <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                  <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                  <subviews>
                      <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IIE-8B-dDU">
                          <rect key="frame" x="27" y="32" width="162" height="21"/>
                          <fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="17"/>
                          <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                          <nil key="highlightedColor"/>
                      </label>
                  </subviews>
                  <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
              </view>
          </objects>
      </document>
      MyTempView.xib

      4. 自定義控件利用delegate觸發事件

      #import "ViewController.h"
      #import "MyView.h"
      
      @interface ViewController () <MyDelegate>
      
      @end
      
      @implementation ViewController
      
      - (void)viewDidLoad {
          [super viewDidLoad];
      
          MyView *view1 = [[MyView alloc] initWithFrame:CGRectMake(30, 30, 250, 300)];
          view1.backgroundColor = [UIColor greenColor];
          view1.delegate = self;
          [self.view addSubview:view1];
      }
      
      - (void)eat:(NSString *)food {
          NSLog(@"wayne eat %@", food);
      }
      
      - (void)read:(NSString *)book {
          NSLog(@"wayne read a book called %@", book);
      }
      @end
      ViewController.m
      #import <UIKit/UIKit.h>
      
      @protocol MyDelegate <NSObject,UICollectionViewDelegate>
      @optional
      - (void)sing:(NSString *)song;
      - (void)read:(NSString *)book;
      @required
      - (void)eat:(NSString *)food;
      @end
      
      @interface MyView : UIView
      
      @property (nonatomic, weak) id <MyDelegate> delegate;
      
      @end
      MyView.h
      #import "MyView.h"
      
      @implementation MyView
      
      - (instancetype)initWithFrame:(CGRect)frame {
          self = [super initWithFrame:frame];
          if(self) {
              [self initDataAndUI];
          }
          return self;
      }
      
      - (void)initDataAndUI {
          UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
          [firstButton setTitle:@"Eat Button" forState:UIControlStateNormal];
          [firstButton setBackgroundColor:[UIColor purpleColor]];
          [firstButton sizeToFit];
          [firstButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
          [self addSubview:firstButton];
      }
      
      - (void)buttonClicked:(id)sender {
      
          [(id<MyDelegate>)self.delegate eat:@"an apple"];
          
          
          [self.delegate read:@"Robinson Crusoe"];
      }
      @end
      MyView.m

      5. NSJSONSerialization的NSJSONReadingOptions參數

      NSJSONReadingMutableContainers -- 返回可變容器,NSMutableDictionary或NSMutableArray

      NSJSONReadingMutableLeaves -- 返回的JSON對象中字符串的值為NSMutableString

      NSJSONReadingAllowFragments -- 允許JSON字符串最外層既不是NSArray也不是NSDictionary,但必須是有效的JSON Fragment

      kNilOptions -- 不設置該參數,返回不可變的NSDictionary

      NSString *str = @"{\"name\":\"wayne\"}";
      
      //設置為kNilOptions后嘗試修改字典內容,會導致報錯
      //NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
      
      NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
      
      [dict setObject:@"tom" forKey:@"name"];
      
      NSLog(@"dict= %@,type= %@",dict,[dict class]);
      示例一
      NSString *num=@"32"; //ok
      num = @"ABC"; //error
      num = @"\"ABC\""; //ok
      
      NSError *error;
      NSData *createdData = [num dataUsingEncoding:NSUTF8StringEncoding];
      id response=[NSJSONSerialization JSONObjectWithData:createdData options:NSJSONReadingAllowFragments error:&error];
      NSLog(@"Response= %@,type= %@",response,[response class]);
      示例二

      6. 一個嵌套JSON解析

      NSString *jsonString = @"{\"Products\":[{\"Appliances\": {\"TV\": {\"SONY\":{\"ProductName\":\"SONY G9\", \"Size\":\"48 inch\"}, \"LETV\":{\"ProductName\":\"S50 Air\", \"Size\":\"50 inch\"} }}}, {\"Digital\": {\"Camera\": {\"Canon\":{\"ProductName\":\"EOS 70D\", \"pixel\":\"2020\"}}}}]}";
      
      NSError *error;
      NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];
      NSLog(@"JSON:%@",json);
      
      if (json) {
          NSArray *products = [json objectForKey:@"Products"];
      
          NSDictionary *appliancesDict = products[0]; //Appliances
          NSLog(@"appliancesDict: %@",appliancesDict);
          NSDictionary *digitalDict = products[1]; //Digital
          NSLog(@"digitalDict: %@",digitalDict);
          
          NSLog(@"Digital:%@",[digitalDict objectForKey:@"Digital"]);
          NSLog(@"Camera:%@",[[digitalDict objectForKey:@"Digital"] objectForKey:@"Camera"]);
          NSLog(@"Canon:%@",[[[digitalDict objectForKey:@"Digital"] objectForKey:@"Camera"] objectForKey:@"Canon"]);
          NSLog(@"ProductName:%@",[[[[digitalDict objectForKey:@"Digital"] objectForKey:@"Camera"] objectForKey:@"Canon"] objectForKey:@"ProductName"]);
          NSLog(@"pixel:%@",[[[[digitalDict objectForKey:@"Digital"] objectForKey:@"Camera"] objectForKey:@"Canon"] objectForKey:@"pixel"]);
      }
      Code

       

      posted @ 2015-02-06 11:22  CoderWayne  閱讀(605)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 午夜激情小视频一区二区| 好吊视频专区一区二区三区| 一区二区三区综合在线视频| 日本中文字幕乱码免费| 九九热在线这里只有精品| 蜜桃麻豆www久久囤产精品| 亚洲av午夜成人片| 无码中文字幕人妻在线一区二区三区| 欧美激情 亚洲 在线| 亚洲日韩精品无码一区二区三区| 国产精品激情av在线播放| 亚洲精品日产AⅤ| 无码乱人伦一区二区亚洲一| 99精品国产中文字幕| 国产高清无遮挡内容丰富| 国产精品视频一区不卡| 亚洲男人AV天堂午夜在| 色av综合av综合无码网站| 十八禁午夜福利免费网站| 无遮挡高潮国产免费观看| 婷婷丁香五月亚洲中文字幕| 亚洲日韩精品一区二区三区| 无码日韩av一区二区三区| 2020精品自拍视频曝光| 国产女人喷潮视频在线观看| 永久免费AV无码国产网站| 精品尤物TV福利院在线网站| 亚洲精品久久无码av片软件| 亚洲男人在线天堂| 亚洲色婷婷一区二区三区| 精品人妻系列无码人妻漫画| 国产免费无遮挡吃奶视频| 久久se精品一区精品二区国产| 国产精品综合av一区二区国产馆| 亚洲爆乳少妇无码激情| 久久羞羞色院精品全部免费| 日韩av熟女人妻一区二| 日本一区二区三区黄色网| 亚洲欧美日韩人成在线播放 | 日韩欧美在线综合网另类| 精品一区二区三区波多野结衣|