iOS筆記

July 27, 2016
作者:dengshuai_super
出處:http://blog.csdn.net/dengshuai_super/article/details/52050398
聲明:轉載請註明作者及出處。


✓   2015.6.4 週四

file’s owner以及outlet與連線的理解

file’s owner 可以看作是xib對應的類,比如view對應的xib文件的file‘s owner
對應的就是view controller的類。

我對file’s owner 的理解:xib文件附屬於一個類,這個類就是xib屬性欄中的custom Class,並且custom Class一般是控制器類A。而file’s owner相當於這個控制器類A。現在需要對控制器A中定義的類 和 xib中的形象化的控制器類B進行連接,只要從file’s owner 拖到對應的控制器B進行連接。這個過程相當對把A中的某個屬性(一般都是定義的類IBOutlet)和B中的控件或者視圖或者控制器對應起來。
而事件的連接的過程則相當於將B中的某個執行動作和A中的某個方法(IBAction)

view和viewController之間的對應關係,需要一個橋樑來進行連接(即,對於一個視圖,他如何知道自己的界面的操作應該由誰來響應),這個橋樑就是File’s
Owner。

選中某個XIB的File’s Owner ,在Inspector中可以看到屬性:File Name和Custom Class,該File’s Owner 就是用來綁定File Name中的xib文件和Custom Class中的ViewController的,在做了這個綁定之後,按住control鍵,拖動File‘s Owner 到xib中的某個控件的時候,就是Custom Class中定義的IBOutlet元素與xib中元素中進行連接的過程,同樣,拖動“xib中的控件的動作”到File’s Owner的時候,就是將xib中該動作的響應與Custom Class中某個IBAction進行連接的過程。

xib文件本身可以看作是一個xml,app啓動的時候會根據xml構造的xib對應的界面及其控件。

✓   2015.6.19週五

http://blog.csdn.net/q199109106q/article/details/8563438/

✓   2015.6.22週一

http://mobile.51cto.com/iphone-388248.htm

4、打開ViewController.m,找到addButton函數,添加以下代碼:

    1.  - (IBAction)addButton:(id)sender { 
    2.      //動態添加一個按鈕 
    3.      CGRect frame = CGRectMake(300, 300, 300, 50);  
    4.      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    5.      button.frame = frame; 
    6.      [button setTitle:@"新添加的動態按鈕" forState: UIControlStateNormal];   
    7.      button.backgroundColor = [UIColor clearColor];   
    8.      button.tag = 2000; 
    9.      [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];   
    10.     [self.view addSubview:button];   
    11. } 

5、在addButton函數後邊添加一個函數:

    1.  //這個是新按鈕的響應函數 
    2.  -(IBAction) buttonClicked:(id)sender {   
    3.      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"  
    4.                                                      message:@"單擊了動態按鈕!"    
    5.                                                     delegate:self    
    6.                                            cancelButtonTitle:@"確定"   
    7.                                            otherButtonTitles:nil];   
    8.      [alert show]; 
    9.      [alert release]; 
    10. } 
    11. 

在深色背景下將狀態條設置成白色:

在老版本的iOS中,狀態欄永遠都是白色風格。而在iOS 7中,我們可以修改每個view controller中狀態欄的外觀。通過UIStatusBarStyle常量可以指定狀態欄的內容是暗色或亮色。默認情況下,狀態欄的顯示是暗色。也就是說,狀態欄上的時間、電池指示器和Wi-Fi信號顯示爲暗色。如果導航欄中使用暗色爲背景

-(UIStatusBarStyle)preferredStatusBarStyle 
{ 
    return UIStatusBarStyleLightContent; 
}

通過tag值獲得相應對象

UITabBarItem *shouye = (UITabBarItem *)[self.view viewWithTag:100];

改變TabBarItem的選中時和未選中時的圖片
UITabBarItem *ti1 = [tabBar.items objectAtIndex:0];
ti1.title = @”夢見”;

ti1.image = [[UIImage imageNamed:@"qr_tabbar_mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
ti1.selectedImage = [[UIImage imageNamed:@"qr_tabbar_mine_hl"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 

http://www.bkjia.com/IOSjc/872299.html
3.以上拖拽工作到此結束,下面要實現我們的業務邏輯和關聯視圖之間的關係,爲了關聯視圖時能找到帶有三個按鈕的視圖,我們需要設置一下該視圖的StoryboardID,入下圖

  4.下面來編寫我們的代碼,上面我們用到了TextField,我們需要處理鍵盤的回收事件,所以我們的ViewController要遵守UITextFiledDelegate協議,實現有關鍵盤的方法
    (1)遵守UITextFieldDelegate協議

#import <UIKit/UIKit.h>   
@interface ViewController : UIViewController<UITextFieldDelegate> 
@end

    (2)在ViewController.m中中進行回調註冊和實現協議中相應的方法,代碼如下:

-(BOOL) textFieldShouldReturn:(UITextField *)textField {     
[self.userName resignFirstResponder];     [self.password resignFirstResponder];    
return YES; 
}   
- (void)viewDidLoad {     
[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.    self.userName.delegate = self;     self.password.delegate = self; 
- }

  5.處理完鍵盤的事兒,就該處理我們當登陸按鈕點擊時回調的事件了,首先在回調方法中獲取TextFiled的值,由值的情況來實現是否進行頁面間的切換。 在頁面切換時我們得關聯兩個頁面中的關係。

- (IBAction)tapButton:(id)sender {           
if ([username isEqualToString:@"admin"] && [password isEqualToString:@"admin"])     
{
//獲取storyboard: 通過bundle根據storyboard的名字來獲取我們的storyboard,         
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];    //由storyboard根據myView的storyBoardID來獲取我們要切換的視圖        
UIViewController *myView = [story instantiateViewControllerWithIdentifier:@"myView"];//由navigationController推向我們要推向的view         
[self.navigationController pushViewController:myView animated:YES];               
}   
}

 代碼說明:關聯兩個View需要三部
1.獲取storyboard: 通過bundle的名獲取bundle, 在通過storyborad的名字來獲取我們的storyboard;
2.在由storyboard獲取storyboardID是myView的View;
3.執行由當前View推向我們獲取到的myView;

使用storyboard,設置tab bar Item的選中圖片(selected Image)
http://blog.csdn.net/sxh1234567/article/details/44984665

                                       9:16


這裏寫圖片描述

http://www.cocoachina.com/ios/20141230/10800.html
快速兼容iPhone5s和6,6plus

✓   2015.6.23 週二
static NSString *CellIdentifier= @"CellIdentifier";

#define PLISTFILENAME @"SpeMerchantPList.plist"

#define PATH  [[NSBundle mainBundle]pathForResource:PLISTFILENAME ofType:nil]

- (void)viewDidLoad {
    [super viewDidLoad];
   // [_SpecialMerchantTableView setBackgroundColor:[UIColor grayColor]];//把背景色改爲黑色背景
    _SpeMerchantInfoArray = [NSArray arrayWithContentsOfFile:PATH];

    [self.tableView registerClass:[UITableViewCell class]  forCellReuseIdentifier:CellIdentifier];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [_SpeMerchantInfoArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    // Configure the cell...
    if ([_SpeMerchantInfoArray count]>0)
    {

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(7, 7, 100, 70)];
        imageView.image = [UIImage imageNamed:_SpeMerchantInfoArray[indexPath.row][0]];
        [cell addSubview:imageView];

        UILabel *TitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(115, 8, 95, 21)];
        TitleLabel.text = _SpeMerchantInfoArray[indexPath.row][1];
        [cell addSubview:TitleLabel];

        UILabel *DateLabel = [[UILabel alloc]initWithFrame:CGRectMake(121, 39, 160, 17)];
        DateLabel.text = _SpeMerchantInfoArray[indexPath.row][2];
        DateLabel.backgroundColor = [UIColor clearColor];
        DateLabel.textColor = [UIColor grayColor];
        DateLabel.font = [UIFont fontWithName:@"STHeiti-Medium.ttc" size:5];
        [cell addSubview:DateLabel];

        UILabel *JuLiLabel = [[UILabel alloc]initWithFrame:CGRectMake(240, 7, 63, 21)];
        JuLiLabel.text = _SpeMerchantInfoArray[indexPath.row][3];
        [cell addSubview:JuLiLabel];

        UIButton *zuobiaoButton = [[UIButton alloc]initWithFrame:CGRectMake(215, 7, 20, 20)];
       // [zuobiaoButton.imageView setImage:[UIImage imageNamed:@"zaixiandaohang"] ];
        [zuobiaoButton setImage:[UIImage imageNamed:@"zaixiandaohang"] forState:UIControlStateNormal];
        [cell addSubview:zuobiaoButton];

        UIButton *moneyButton = [[UIButton alloc]initWithFrame:CGRectMake(303, 7, 20, 20)];
        //[moneyButton.imageView setImage:[UIImage imageNamed:@"caifu"] ];
        [moneyButton setImage:[UIImage imageNamed:@"caifu"] forState:UIControlStateNormal ];
        [cell addSubview:moneyButton];


    }


    return cell;
}
✓   2015.6.24 週三

http://www.cocoachina.com/bbs/read.php?tid-281373.html

//自定義按鈕,文字在左,圖片在右
HHButton *btn = [[HHButton alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];//寬100,高30只是最大的顯示面積。 
[btn setTitle:@"山東省青島市" forState:UIControlStateNormal]; 
[btn setImage:[UIImage imageNamed:@"小三角"  forState:UIControlStateNormal]; 


 [[UITabBar appearance] setSelectedImageTintColor:[UIColor orangeColor]];

init-初始化程序
viewDidLoad-加載視圖
viewWillAppear-UIViewController對象的視圖即將加入窗口時調用;
viewDidApper-UIViewController對象的視圖已經加入到窗口時調用;viewWillDisappear-UIViewController對象的視圖即將消失、被覆蓋或是隱藏時調用;viewDidDisappear-UIViewController對象的視圖已經消失、被覆蓋或是隱藏時調用;didReceiveMemoryWarning - 內存不足時候調用這個

當利用ScrollView實現滾動頁面時,初始化ScrollView時CGRectMake當width要設置成ScreenWidth,而它的ContentSize的寬度設置成實際內容所需要的寬度,例如有3張圖片則設置成3倍圖片的寬度。

http://www.cnblogs.com/woainilsr/archive/2012/03/28/2421881.html

length = (self.view.frame.size.width-40)/6;
    Scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, smallScroll.frame.origin.y+smallScroll.frame.size.height, screenWidth, length*1.8)];
    Scroll.bounces = NO;
    Scroll.backgroundColor=[UIColor whiteColor];
    Scroll.showsHorizontalScrollIndicator = NO;
    Scroll.pagingEnabled = YES;
    Scroll.delegate = self;
    Scroll.contentSize = CGSizeMake(self.view.frame.size.width*2, length*1.8);
    [scrollView addSubview:Scroll];

Scroll.contentSize = CGSizeMake(self.view.frame.size.width*buttonTitleArr.count/4, length*1.8);

設置pageControl:

    pageControl2 = [[UIPageControl alloc]initWithFrame:CGRectMake(screenWidth/2-35, Scroll.bounds.origin.y+Scroll.bounds.size.height+smallScroll.bounds.size.height-10, 70, 10)];
    pageControl2.numberOfPages = buttonTitleArr.count/4 ;
    pageControl2.currentPage = 0;
    pageControl2.currentPageIndicatorTintColor = [UIColor colorWithRed:255/255.0f green:91/255.0f blue:119/255.0f alpha:1];
    pageControl2.pageIndicatorTintColor = [UIColor grayColor];
    [pageControl2 addTarget:self action:@selector(btnPageControl2:) forControlEvents:UIControlEventValueChanged];
    pageControll2=YES;
    [scrollView addSubview:pageControl2];

    [self collectionView];
✓   2015.6.25 週四

http://www.cnblogs.com/top5/archive/2012/05/17/2506623.html

//下面代碼實現進度輪的啓動和停止:
- (void)viewDidLoad
{
    activity = [[UIActivityIndicatorViewalloc] initWithFrame:CGRectMake(0, 0, 30, 30)];//指定進度輪的大小
    [activitysetCenter:CGPointMake(160, 140)];//指定進度輪中心點
    [activitysetActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];//設置進度輪顯示類型
    [self.viewaddSubview:activity];
    [superviewDidLoad];
}

//button點擊所觸發的方法。 啓動或關閉進度輪。
- (IBAction)startOrStop:(id)sender{
    if([activityisAnimating]){
        [activitystopAnimating];
    }
    else
        [activitystartAnimating];
}

ios uiscrollview和 pagecontrol怎麼結合使用
http://zhidao.baidu.com/link?url=Rngr26W9A3aO3C68RSmisJ1jCLqwJj_xiiifw4lZtiinChXiC__Y1-AAXcMFyRkBPMo8L_PDJShFNMgSqL42YUvRHwT6_Pepcmku0zF3bjq

@interface RootViewController : UIViewController<UIScrollViewDelegate>

{

    UIScrollView *_scrollView;

    NSMutableArray *slideImages;

    UIPageControl *_page;

}


@end
#import "RootViewController.h"


@interface RootViewController ()


@end


@implementation RootViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];



    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 320, 240)];

    _scrollView.bounces = NO;

    _scrollView.pagingEnabled = YES;

    _scrollView.delegate = self;

    _scrollView.contentOffset = CGPointMake(320, 0);

    _scrollView.contentSize = CGSizeMake(1920,240);

    _scrollView.showsVerticalScrollIndicator =NO;

    _scrollView.showsHorizontalScrollIndicator = NO;

    _scrollView.userInteractionEnabled = YES;

    [self.view addSubview:_scrollView];

    [_scrollView release];



    slideImages = [[NSMutableArray alloc]initWithObjects:@"1.jpeg",@"2.jpg",@"3.jpeg",@"4.jpeg", nil];



    UIImageView *imageView = [[UIImageView alloc]

                              initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:([slideImages count]-1)]]];

    imageView.frame = CGRectMake(0, 0, 320, 240);

    [_scrollView addSubview:imageView];

    [imageView release];



    for (int i = 0;i<[slideImages count];i++) {

        //loop this bit

        UIImageView *imageView = [[UIImageView alloc]

                                  initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:i]]];

        imageView.frame = CGRectMake(320*i+320, 0, 320, 240);

        imageView.userInteractionEnabled = YES;

        [_scrollView addSubview:imageView];

        [imageView release];

    }



    imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:0]]];

    imageView.frame = CGRectMake(320*5, 0, 320, 240);

    [_scrollView addSubview:imageView];



    [imageView release];





    _page = [[UIPageControl alloc]initWithFrame:CGRectMake(240, 230, 70, 30)];

    _page.numberOfPages = 4;

    _page.currentPage = 0;



//    _page.backgroundColor = [UIColor grayColor];

    [_page addTarget:self action:@selector(pageAction) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:_page];

    [_page release];

// Do any additional setup after loading the view.

}



- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    int currentPage = (_scrollView.contentOffset.x - _scrollView.frame.size.width

                             / ([slideImages count]+2)) / _scrollView.frame.size.width + 1;

    NSLog(@"%d",currentPage);

    if (currentPage==0) {

        [_scrollView scrollRectToVisible:CGRectMake(320*4, 0, 320, 240) animated:NO];

    }

    else if (currentPage==([slideImages count]+1)) {

            //如果是最後+1,也就是要開始循環的第一個

            [_scrollView scrollRectToVisible:CGRectMake(320, 0, 320, 240) animated:NO];

        }

}


- (void)scrollViewDidScroll:(UIScrollView *)sender

{

    int page = _scrollView.contentOffset.x/320-1;

    _page.currentPage = page;

}


-(void)pageAction

{

    int page = _page.currentPage;

    [_scrollView setContentOffset:CGPointMake(320 * (page+1), 0)];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (void)dealloc {



    [slideImages release];

    [super dealloc];

}


@end
✓   2015.6.26 週五

.a文件是LINUX系統中的靜態鏈接庫文件。所謂靜態鏈接是指把要調用的函數或者過程鏈接到可執行文件中,成爲可執行文件的一部分。當多個程序都調用相同函數時,內存中就會存在這個函數的多個拷貝,這樣就浪費了寶貴的內存資源。.so文件是共享庫文件(動態鏈接)。動態鏈接所調用的函數代碼並沒有被拷貝到應用程序的可執行文件中去,而是僅僅在其中加入了所調用函數的描述信息(往往是一些重定位信息),僅當應用程序被裝入內存開始運行時,在操作系統的管理下,纔在應用程序與相應的.so之間建立鏈接關係。
.a文件是多個.o文件的組合。.o文件就是對象文件,裏面包含的內容就是01這樣的機器可執行的指令,當程序要執行時還需要進行鏈接(link).鏈接就是把多個.o文件鏈成一個可執行文件。

真機測試添加設備的步驟
http://my.oschina.net/u/1245365/blog/196420

CLLocationManager的例子
http://blog.csdn.net/pinklpig/article/details/7191347

想得到定點的信息,主要使用兩個類,CLLocationManager, CLLocationManagerdelegate協議,

m文件內容如下
1、先實例化一個CLLocationManager,同時設置委託及精確度等。

CCLocationManager *manager = [[CLLocationManager alloc] init];//初始化定位器
[manager setDelegate: self];//設置代理
[manager setDesiredAccuracy: kCLLocationAccuracyBest];//設置精確度
[manager startUpdatingLocation];//開啓位置更新

2、接着實現CLLocationMangerDelegate協議的兩個方法就可以了:

//定位時候調用
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation ;

//定位出錯時被調
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;

iphone練習之手勢識別(雙擊、捏、旋轉、拖動、划動、長按)UITapGestureRecognizer

運用scrollView時一定要注意他的frame是顯示的區域,一般爲屏幕寬和高,他的內容區域contentSize也就是實際滾動的區域要設置好。否則不能滾動。

//設置scrollView的區域
    scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [scrollView setContentSize:CGSizeMake(screenWidth, 2300)];
    scrollView.backgroundColor = [UIColor colorWithRed:234/255.0f green:234/255.0f blue:234/255.0f alpha:1];
✓   2015.6.27 週六
        _gouwucheButton=[[UIButton alloc]initWithFrame: CGRectMake(self.bounds.origin.x+self.bounds.size.width-_tupian.frame.size.width/2.8, _salePriceLabel.frame.origin.y ,_tupian.frame.size.width/3, _priceLabel.frame.size.height)];
        _gouwucheButton.layer.cornerRadius = 3.0;//設置圓角button
       // [_gouwucheButton setTintColor:[UIColor orangeColor]];
        [_gouwucheButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal ];
        //_gouwucheButton.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
        [_gouwucheButton setTitle:@"加入購物車" forState:UIControlStateNormal];
        //_gouwucheButton.titleLabel.text = @"加入購物車";
        _gouwucheButton.titleLabel.textColor = [UIColor orangeColor];
        _gouwucheButton.titleLabel.font =[UIFont systemFontOfSize:10];
        _gouwucheButton.layer.borderColor = [UIColor orangeColor].CGColor;//邊框顏色,要爲CGColor
        _gouwucheButton.layer.borderWidth = 1;//邊框寬度
        [self addSubview:_gouwucheButton];

用main.storyboard爲不同尺寸設備做適配
http://blog.csdn.net/liangliang103377/article/details/40082255

iOS7自動佈局一
http://www.cocoachina.com/industry/20131203/7462.html

iOS7自動佈局二
http://www.it165.net/pro/html/201409/22410.html

Xcode6中自動佈局autolayout和sizeclass的使用
http://www.cocoachina.com/ios/20140915/9623.html

✓   2015.6.29 週一
 //設置價格
        //tempGoodView.priceLabel.backgroundColor = [UIColor blackColor];
        tempGoodView.priceLabel.text =[NSString stringWithFormat:@" ¥%@元",model2.price];
        // 根據priceLabel的字數設置他的寬度
        CGSize tempsize = [tempGoodView.priceLabel.text sizeWithFont:tempGoodView.priceLabel.font
                                                          constrainedToSize:tempGoodView.priceLabel.frame.size lineBreakMode:tempGoodView.priceLabel.lineBreakMode];

        tempGoodView.priceLabel.frame = CGRectMake(tempGoodView.priceLabel.frame.origin.x, tempGoodView.priceLabel.frame.origin.y, tempsize.width, tempsize.height);

        //設置打折之前價格
        //tempGoodView.salePriceLabel.backgroundColor =[UIColor blackColor];
        tempGoodView.salePriceLabel.frame = CGRectMake(tempGoodView.priceLabel.frame.origin.x+tempGoodView.priceLabel.frame.size.width, tempGoodView.salePriceLabel.frame.origin.y, tempGoodView.salePriceLabel.frame.size.width, tempGoodView.salePriceLabel.frame.size.height);
        //tempGoodView.salePriceLabel.textAlignment = NSTextAlignmentCenter;

        NSString *oldPrice = [NSString stringWithFormat:@"%@元",model2.YuanPrice];
        NSUInteger length2 = [oldPrice length];

//添加中間的刪除線
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPrice];
        [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length2)];
        [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor colorWithWhite:0.4 alpha:1] range:NSMakeRange(0, length2)];
        [tempGoodView.salePriceLabel setAttributedText:attri];
✓   2015.6.30 週二    請假


✓   2015.7.1   週三
UIButton* xiaoqubutton=[[UIButton alloc]initWithFrame:CGRectMake(screenWidth/2+7, 11, 85, 20)];
    xiaoqubutton.titleLabel.font =[UIFont systemFontOfSize:8];
    [xiaoqubutton.titleLabel setTextColor:[UIColor whiteColor]];

    xiaoqubutton.imageEdgeInsets = UIEdgeInsetsMake(1, 64, 0, 7);//設置三角小圖標的位置
    [xiaoqubutton setImage:[UIImage imageNamed:@"sanjiao3"] forState:UIControlStateNormal];

    //xiaoqubutton.layer.borderColor = [UIColor orangeColor].CGColor;//邊框顏色,要爲CGColor
    //xiaoqubutton.layer.borderWidth = 1;//邊框寬度
    xiaoqubutton.layer.cornerRadius = 5.0;
    xiaoqubutton.backgroundColor = [UIColor orangeColor];
✓   2015.7.2   週四

設置tabBarItem的圖像時,圖片爲60x60像素,命名時用“名稱+@2x”這樣就可以很好的適應大小了

tabBarItem0.selectedImage = [[UIImage imageNamed:@"shouye01@2x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    tabBarItem0.image =[[UIImage imageNamed:@"shouye02@2x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem0.title=@"首頁";

1.普通分頁滑動

    myScrollView = [[UIScrollViewalloc]initWithFrame: CGRectMake(0,0,320,460)];
     [myScrollViewsetContentSize:CGSizeMake(pageWidth*3,460)];
    [myScrollViewsetBackgroundColor:[UIColorscrollViewTexturedBackgroundColor]];
    [myScrollViewsetPagingEnabled:YES];//當此屬性設置爲YES時,才能自動分頁
    [self.viewaddSubview:myScrollView];


[image sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"1@2x"]];//placeholderImage是圖片加載完畢顯示之前顯示的圖像。起到緩衝的效果
✓   2015.7.3   週五

代理使用:http://blog.csdn.net/huifeidexin_1/article/details/7567731

@protocol MyDelegate
-(void)buyIphone:(NSString *)iphoneType money:(NSString *)money;

@end
@interface My : NSObject
{
    id<MyDelegate> deleage;
}
@property(assign,nonatomic)id<MyDelegate> delegate;
@end

代碼中聲明瞭一個協議 名叫Mydelegate,在其中有一個buyIphone方法,即一個委託項。當我要購買手機的時候只需要通過delegate 調用 BuyIphone方法即可.
如下:

-(void)willbuy
{
    [delegate buyIphone:@"iphone 4s" money:@"4888"];

}

我不必關心誰現實了這一委託,只要實現了這個委託的類,並且buyIphone是聲明的委託中必須實現的方法,那麼就一定能夠得到結果.
例如:商人類實現了這一委託(用表示實現)

#import <Foundation/Foundation.h>
#import "My.h"
@interface Business : NSObject<MyDelegate>

@end
//然後在 @implementation Business 中調用 buyIphone方法#import "Business.h"

@implementation Business

-(void)buyIphone:(NSString *)iphoneType money:(NSString *)money
{
    NSLog(@"手機有貨,這個價錢賣你了,發貨中!!");
}
@end

如何完全自定義NavigationBar

NavigationBar是很常用的一個元素,所以常常需要進行自定義操作,而一種比較直觀的方式就是,先定義一個類NavigationBar繼承自 UINavigationBar,而這個NavigationBar的內部內容則是比較複雜的了,裏面添加我們需要的所有的navigationBar 的樣式,而且使得這些view的尺寸都是整個NavigationBar的尺寸,然後再進行內部view的構建就可以了,而需要進行切換的時候就進行這些view之間的顯示和隱藏的切換就可以了,最好使用一些動畫,前面的文中有提供動畫流暢的保證方式,現在新建一個HomeNavigationController 繼承自 UINavigationController,並且在這個類的實現中這樣操作

@implementation HomeNavigationController
-(instancetype)init
{
    self = [super initWithNavigationBarClass:[Navigationbar class] toolbarClass:nil];
    if (self) {
        self.delegate = self;
    }
    return self;
}

這樣的話就將HomeNavigationController的導航欄的樣式進行了確定了。而爲了能進行子控制器的導航欄的正確顯示,最好在HomeNavigationController中聲明一個

@protocol SecretPresentableViewController <NSObject>
@optional
- (void)willPresentWithNavigationBar:(Navigationbar *)navigationBar;
@end

而那些想要擁有這個導航欄的自控制器只需要實現協議就可以了,而NavigationBar中的多個view的左右按鈕以及中間都可以完全的自定義了,而事件 的傳遞則使用block的方式,這裏提供其中一個自定義view的h定義方式

@interface HomeNavigationView : UIView
@property(nonatomic, copy) void (^didTapComposeBlock)(void);
@property(nonatomic, copy) void (^didTapNotificationsBlock)(void);
@property(nonatomic, copy) void (^didTapChatBlock)(void);
@property(nonatomic, copy) void (^didTapScrollToTopBlock)(void);
@property(nonatomic, copy) void (^didTapNewThemeTopBlock)(void);
@property (nonatomic, strong) UILabel* titleLabel;
@property (nonatomic, strong) UIButton *tipsNewThemeBtn;
@property (nonatomic, strong) UIButton *unreadLeftV;
@end

而在m文件中只要對按鈕添加監聽就可以了,例子是

#pragma private
-(void)left:(id)sender
{
    if (_didTapNotificationsBlock) _didTapNotificationsBlock();

}
在擁有navigationBar 的控制器中對具體的block進行處理
navigationBar.homeNavigationView.didTapNotificationsBlock = ^{
        [self left:nil];
    };

而裏面使用的這個left:方法則正是這個控制器中的具體的處理方法(push,modal,或者按鈕的消失,lable的隱藏等等的點擊相應等等),這樣的話就實現了自定義bar的同時而且實現了bar和控制器之間的無縫銜接。更加方便的進行自定義的操作,但同時也可以完全實現系統提供bar的所有功能等等,而這個具體的實現過程很有可能就是apple自己內部的實現方式,因爲apple很推薦我們使用block而這種bar和viewcontrol的傳遞消息的方式感覺這是最優秀的了。

✓   2015.7.4   週六

Swift基礎--調用第三方OC項目
http://blog.csdn.net/jwzhangjie/article/details/40421629

✓   2015.7.6   週一
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==1) {
        if (buttonIndex ==1) {
            AdViewController *ad = [[AdViewController alloc]init];
            ad.AdUrl = label.text;
            [self.navigationController pushViewController:ad animated:YES];
        }
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

//webview中頁面返回
-(void)back
{
    if (webView.canGoBack==YES) {
        [webView goBack];
    }
}




//添加索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    if (tableView.tag==1) {
        return self.keysArray ;
    }else{
        return nil;
    }

}

//標題,區名,相當於鍵值
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (tableView.tag == 1) {
        return self.keysArray[section];
    }else{
        return nil;
    }

}


//    1、調用 自帶mail
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
//
//    2、調用 電話phone
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];
//
//    3、調用 SMS
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
//
//    4、調用自帶 瀏覽器 safari
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];

//訂閱通知,當在BIDKeyboardDialViewController中新建聯繫人時通知我,我便執行重新加載數據方法
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getInfo:) name:@"updateData" object:nil];


//發送通知,通知通訊錄增加了聯繫人,讓他更新數據
    [[NSNotificationCenter defaultCenter]postNotificationName:@"updateData" object:nil ];

多線程
http://my.oschina.net/aofe/blog/270093
dispatch_async(dispatch_queue_create(“com.liujie.ZMLIVE”,NULL), ^{

    dispatch_async(dispatch_get_main_queue(), ^{
        //爲商品區域整個頁面加載數據
        [self setInfoForAllNormalGoodsView:GoodsAreaDic];
    });
});

UICollectionView實現分組顯示
http://blog.csdn.net/zttjhm/article/details/37817719

UICollectionView實現自定義cell
http://www.cnblogs.com/ios8/p/iOS-UICollectionView.html

scrollView刷新
https://github.com/CoderMJLee/MJRefresh

✓   2015.7.7   週二

Xcode 6 LaunchImage 載入界面標準大小
LaunchImage啓動頁面大小
http://blog.it985.com/3335.html
這裏寫圖片描述
iPhone Portrait iOS 8-Retina HD 5.5 (1242×2208) @3x
iPhone Portrait iOS 8-Retina HD 4.7 (750×1334) @2x
iPhone Portrait iOS 7,8-2x (640×960) @2x
iPhone Portrait iOS 7,8-Retina 4 (640×1136) @2x
iPhone Portrait iOS 5,6-1x (320×480) @1x
iPhone Portrait iOS 5,6-2x (640×960) @2x
iPhone Portrait iOS 5,6-Retina4 (640×1136) @2x

定位

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "GDataXMLNode.h"
@interface HomeViewController : UIViewController<CLLocationManagerDelegate>
@property(nonatomic,retain)CLLocationManager *locationManager;
@property (nonatomic,retain) UILabel * cityLabel;


@end
//判斷定位操作是否被允許
    if([CLLocationManager locationServicesEnabled]) {
        self.locationManager = [[CLLocationManager alloc] init] ;
        self.locationManager.delegate = self;
        if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
            [_locationManager requestAlwaysAuthorization];
        }
        // 開始定位
        [self.locationManager startUpdatingLocation];

    }else {
        //提示用戶無法進行定位操作
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                  @"提示"message:@"定位不成功 ,請確認開啓定位" delegate:nil cancelButtonTitle:@"取消"otherButtonTitles:@"確定",nil];
        [alertView show];
    }

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    //此處locations存儲了持續更新的位置座標值,取最後一個值爲最新位置,如果不想讓其持續更新位置,則在此方法中獲取到一個值之後讓locationManager stopUpdatingLocation
    CLLocation *currentLocation = [locations lastObject];
    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    [user setValue:[NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude] forKey:@"lat"];
    [user setValue:[NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude] forKey:@"lon"];
    NSLog(@"%f %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
    //獲取當前所在的城市名
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    //根據經緯度反向地理編譯出地址信息
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *array, NSError *error)
     {
         if (array.count >0)
         {
             CLPlacemark *placemark = [array objectAtIndex:0];
             //將獲得的所有信息顯示到label上

             //獲取城市
             NSString *city = placemark.locality;
             NSLog(@"%@",placemark.locality);
             if (!city) {
                 //四大直轄市的城市信息無法通過locality獲得,只能通過獲取省份的方法來獲得(如果city爲空,則可知爲直轄市)
                 city = placemark.administrativeArea;

             }

             _cityLabel.text= city;
             [user setValue:[NSString stringWithFormat:@"%@", _cityLabel.text]forKey:@"city"];
             [self importScheduleIntoServiceWithgetlon:[NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude] andlat:[NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude]];//根據經緯度執行
             NSLog(@"%@",city);

         }
         else if (error ==nil && [array count] ==0)
         {
             NSLog(@"No results were returned.");
         }
         else if (error !=nil)
         {
             NSLog(@"An error occurred = %@", error);

         }
     }];

    //系統會一直更新數據,直到選擇停止更新,因爲我們只需要獲得一次經緯度即可,所以獲取之後就停止更新
    [manager stopUpdatingLocation];
    //    [self.navigationController popViewControllerAnimated:YES];
}
- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error {
    if (error.code ==kCLErrorDenied) {
        // 提示用戶出錯原因,可按住Option鍵點擊 KCLErrorDenied的查看更多出錯信息,可打印error.code值查找原因所在
    }
}

判斷網絡是否連接正常
http://www.cnblogs.com/mrhgw/archive/2012/08/01/2617760.html

typedef enum {
    NotReachable = 0,
    ReachableViaWiFi,
    ReachableViaWWAN
} NetworkStatus;

我記得NotReachable是0吧,wifi是1,3g是2。
3g切換到wifi時 順序爲 201,
wifi切到3g時爲102

MBProgressHUD的基本使用
http://blog.csdn.net/qjlhlh/article/details/8127436

再談iOS 7的手勢滑動返回功能

http://blog.csdn.net/jasonblog/article/details/28282147

iOS8自定義動畫專場上手指南
http://www.360doc.com/content/15/0126/12/8772388_443794982.shtml

✓   2015.7.8   週三

第三方類庫的使用
http://www.360doc.com/content/13/1211/08/14615320_336245146.shtml

http://www.open-open.com/lib/view/open1338688775312.html
因爲iOS SDK相對比較底層,所以開發者就得受累多做一些體力活。不過幸運的是,有很多第三方的類庫可以用來簡化很多不必要的工作.經過作者團隊的慎重討論,他們 評選出了10款能夠極大提高iOS開發效率的類庫,根據原文作者的評價來看,基本上有了這10款工具,做iOS開發就真的跟泡Cocoa一樣了。
MBProgressHUD(進度指示符庫)
地址:https://github.com/jdg/MBProgressHUD
蘋果的應用程序一般都會用一種優雅的,半透明的進度顯示效果,不過這個API是不公開的,因此你要是用了,很可能被清除出AppStore。而 MBProgressHUD提供了一個替代方案,而且在用戶角度上,實現的效果根本看不出和官方程序有什麼差別。同時還提供了其他附加功能,比如虛擬進展 指示符,以及完成提示信息。整合到項目裏也很容易,這裏不細談了。
ASIHttpRequest(HTTP Network庫)
地址:http://allseeing-i.com/ASIHTTPRequest/
iPhone當然也有自己的HTTP Network API,那爲什麼要用ASIHttpRequest呢?因爲官方的API簡直跟話癆似的,太羅嗦了!ASIHttpRequest庫極大的簡化了網絡通 信,提供更先進的工具,什麼文件上傳工具,重定向處理工具、驗證工具、等等。只要你手頭的東西跟HTTP有關,用這個絕對能讓你感覺道生活有美好!先看一 段代碼就體會到了。

    1   (void) loadAppDevMag    
    2   {    
    3      NSURL *url = [NSURL URLWithString:@"http://www.appdevmag.com"];    
    4      ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];    
    5      [request setDelegate:self];    
    6      [request startAsynchronous];    
    7   }    
    8       
    9   - (void)requestFinished:(ASIHTTPRequest *)request    
    10  {    
    11     // Use when fetching text data    
    12     NSString *responseString = [request responseString];    
    13  }   

JSON Framework(JSON支持)
地址:http://stig.github.com/json-framework/
如果你做的應用和網站服務器有交互,那就得用到JSON了。但事實上,iOS平臺的原生類庫根本就不支持JSON,這就略犀利了吧?不過JSON框 架滿足了你的所有需求,包括一個解析器將JSON字符串解析成對象;以及一個生成器從對象生成字符串。這個庫根本就是太流行了,JSON提過很多次了,具 體特點就不多講了,所謂“一段代碼勝千言”,下面用一段代碼演示一下吧。

    1   // JSON string -> NSDictionary    
    2       
    3   NSString *jsonString = @"{\"foo\": \"bar\"}";    
    4       
    5   NSDictionary *dictionary = [jsonString JSONValue];    
    6       
    7   NSLog(@"Dictionary value for \"foo\" is \"%@\"", [dictionary objectForKey:@"foo"]);    
    8       
    9   // NSDictionary -> JSON string    
    10      
    11  NSString *newJsonString = [dictionary JSONRepresentation];   

Flurry(詳盡的使用統計)

地址:http://www.flurry.com/product/analytics/index.html
這裏寫圖片描述
通過Furry你可以得到應用的用戶人數,用戶活躍度,用戶來源等統計信息。但是他最厲害的地方是,你可以追蹤應用本身的事件和錯誤記錄,所有這些 數據都會在一個類似Google Analytics的界面上顯示,這樣就很容易掌握用戶的行爲和出現的問題。當然,這個星球上很多統計工具,但是這款是作者個人比較推崇的解決方案。
RegexKitLite(正則表達式支持)
地址:http://regexkit.sourceforge.net/RegexKitLite/
正則表達式大家都知道。但是iPhone SDK居然當他不存在?這怎麼能忍啊!果斷用RegexKitLite。雖然叫的是Lite,但是功能很full。示例代碼。

    1   // finds phone number in format nnn-nnn-nnnn    
    2   NSString *regEx = @"[0-9]{3}-[0-9]{3}-[0-9]{4}";    
    3   for(NSString *match in [textView.text componentsMatchedByRegex:regEx]) {    
    4       NSLog(@"Phone number is %@", match);    
    5   }  

Facebook iOS SDK(Facebook API類庫)
這裏寫圖片描述
地址:https://github.com/facebook/facebook-ios-sdk
大體來講就是iPhone上的Facebook login,完全支持Facebook Graph API和the older REST api。如果你的應用跟Facebook有關,相信我,用這個吧。
SDWebImage(簡化網絡圖片處理)
地址:https://github.com/rs/SDWebImage
用SDWebImage調用網站上的圖片,跟本地調用內置在應用包裏的圖片一樣簡單。操作也很簡單,舉例說明
1 [imageView setImageWithURL:[NSURL URLWithString:
@"http://example.com/image.png"]];

類似的功能在Three20裏也有,這個過會再說。相比而言,SDWebImage主要是提供一個小而精的簡捷方便的解決方案
GData client(iPhone上所有Google相關服務的類庫)
地址:http://code.google.com/p/gdata-objectivec-client/
名字就說明一切了。跟Google相關的,值得一提的是,這個項目很開放。有很多示例程序供下載。
CorePlot(2D圖形繪圖儀)
這裏寫圖片描述
地址:http://code.google.com/p/core-plot/
CorePlot有很多解決方案將你的數據可視,同時也會提供各種迷人的圖形效果,比如棒狀圖、餅狀圖、線狀圖等等,在他們網站上也提供了大量的範例圖形,很多股票價格應用,遊戲分數,個人財務管理都在用。
Three20(通用iOS庫)
這裏寫圖片描述
地址:https://github.com/facebook/three20
這裏寫圖片描述
Three20類庫是Facebook自己做的,大而全是他最大的特色。把他整合到已有的項目中可能得費點周折,不過如果一開始你就用上了Three20,尤其是牽扯到很多web相關的項目的時候,你就能深刻體會到神馬叫給力了。
其他類庫
無論是與Web交互的API、可視化數據、加載網上的圖片或創建一個社會功能的應用程序,這裏列出的庫等功能使開發更容易。如果你是一個iOS開發人員,在你的下一個項目開始之前,你一定要檢查有沒有使用這些庫。

http://blog.sina.com.cn/s/blog_6d01cce301016tof.html

KissXml——xml解析庫
相關教程:http://www.iteye.com/topic/625849
http://sencho.blog.163.com/blog/static/83056228201151743110540/
很方便的一個xml解析器,支持Xpath查詢。

skpsmtpmessage——Quick SMTP郵件發送
svn checkout http://skpsmtpmessage.googlecode.com/svn/trunk/ skpsmtpmessage-read-only
github: git clone https://github.com/kailoa/iphone-smtp.git
相關教程:http://disanji.net/2011/01/28/skpsmtpmessage-open-source-framework/
skpsmtpmessage 是由Skorpiostech, Inc.爲我們帶來的一個SMTP協議的開源實現,使用Objective-c 實現,iOS系統的項目可以直接調用

jsonframework——JSON支持
相關教程:http://blog.csdn.net/xiaoguan2008/article/details/6732683
它是一個開源框架,基於BSD協議發佈。由於json-framework是開放源代碼的,當你需要使用它時你只需將json的源代碼加入到你的工程中。
ASIHttpRequest——HTTP Network庫
ASIHttpRequest庫極大的簡化了網絡通 信,提供更先進的工具,例如文件上傳工具,重定向處理工具、驗證工具、等等。
MBProgressHUD——進展指示符庫
蘋果的應用程序一般都會用一種優雅的,半透明的進度顯示效果,不過這個API是不公開的,因此你要是用了,很可能被清除出AppStore。而 MBProgressHUD提供了一個替代方案,而且在用戶角度上,實現的效果根本看不出和官方程序有什麼差別。同時還提供了其他附加功能,比如虛擬進展 指示符,以及完成提示信息。整合到項目裏也很容易,這裏不細談了。
zxing——二維碼掃描庫
支持條形碼/二維碼掃描的圖形處理庫,這是一個java庫,在android上的功能比較完整。同時該庫也支持ios,但只能支持二位條形碼的掃描。
kal——iPhone日曆控件
一個類似於ios系統默認日曆開源日曆庫,支持添加事件,自定義日曆樣式等功能。
Facebook iOS SDK——Facebook API類庫
大體來講就是iPhone上的Facebook login,完全支持Facebook Graph API和the older REST api。
shareKit——分享庫
相關demo:http://www.cocoachina.com/bbs/read.php?tid-71760.html
分享到開心,豆瓣,騰訊,新浪微博的api所用到的強大的分享庫。
SDWebImage——簡化網絡圖片處理
用SDWebImage調用網站上的圖片,跟本地調用內置在應用包裏的圖片一樣簡單。操作也很簡單。
GData client——iPhone上所有Google相關服務的類庫
名字就說明一切了。跟Google相關的,值得一提的是,這個項目很開放。有很多示例程序供下載。
CorePlot——2D圖形繪圖儀
CorePlot有很多解決方案將你的數據可視。同時也會提供各種迷人的圖形效果,比如棒狀圖、餅狀圖、線狀圖等等,在他們網站上也提供了大量的範例圖形,很多股票價格應用,遊戲分數,個人財務管理都在用。
Three20——類似於Facebook的優秀的UI庫
Three20類庫是Facebook自己做的,大而全是他最大的特色。把他整合到已有的項目中可能得費點周折,不過如果一開始你就用上了Three20,尤其是牽扯到很多web相關的項目的時候,你就能深刻體會到神馬叫給力了。
FMDatabase——SQLite的Objective-C封裝
是SQLite的C API對初學者來說實在太麻煩太瑣碎,難度太高。FMDB說穿了其實只是把C API包裝成簡單易用的Objective-C類。對於SQLite初學者來說,大大減低了上手的難度。有了FMDB,寫程式時只要專心在SQLite的語法上,而不用去理那堆有看沒有懂的C API,實在是件快樂的事情。

IOS學習:常用第三方庫(GDataXMLNode:xml解析庫)
一、GDataXMLNode說明

GDataXMLNode是Google提供的用於XML數據處理的類集。該類集對libxml2–DOM處理方式進行了封裝,能對較小或中等的xml文檔進行讀寫操作且支持XPath語法。

使用方法:
1、獲取GDataXMLNode.h/m文件,將GDataXMLNode.h/m文件添加到工程中
2、向工程中增加“libxml2.dylib”庫
3、在工程的“Build Settings”頁中找到“Header Search Path”項,添加/usr/include/libxml2”到路徑中
4、添加“GDataXMLNode.h”文件到頭文件中,如工程能編譯通過,則說明GDataXMLNode添加成功

二、GDataXMLNode示例

示例:
[html] view plaincopy

1   <root>  
2        <name value="wusj"/>  
3        <age>24</age>  
4   </root>  

對此xml文件進行解析

[cpp] view plain copy

    1   NSString *xmlPath = [[NSBundlemainBundle] pathForResource:@"test"ofType:@"xml"];  
    2       NSString *xmlString = [NSStringstringWithContentsOfFile:xmlPath encoding:NSUTF8StringEncodingerror:nil];  
    3       GDataXMLDocument *xmlDoc = [[GDataXMLDocumentalloc] initWithXMLString:xmlString options:0error:nil];  
    4       GDataXMLElement *xmlEle = [xmlDoc rootElement];  
    5       NSArray *array = [xmlEle children];  
    6       NSLog(@"count : %d", [array count]);  
    7        
    8       for (int i = 0; i < [array count]; i++) {  
    9           GDataXMLElement *ele = [array objectAtIndex:i];  
    10            
    11          // 根據標籤名判斷  
    12          if ([[ele name] isEqualToString:@"name"]) {  
    13              // 讀標籤裏面的屬性  
    14              NSLog(@"name --> %@", [[ele attributeForName:@"value"] stringValue]);  
    15          } else {  
    16              // 直接讀標籤間的String  
    17              NSLog(@"age --> %@", [ele stringValue]);  
    18          }  
    19           
    20      }  
運行結果:
    ![這裏寫圖片描述](https://img-blog.csdn.net/20160727234234579)


三、GDataXMLNode方法小結

 最終的數據讀出都是在GDataXMLElement對象中讀出的,以下方法均爲GDataXMLElement類的方法
 1、name方法,取標籤名 e.g name標籤的名稱“name”
 2、attributeForName: 取屬性結點 再調stringValue即可取到屬性值 e.g name標籤中的value屬性
 3、stringValue: 取標籤間的字符串值  e.g: age間的24



✓   2015.7.9   週四

UICollectionView基礎

http://www.cnblogs.com/wayne23/p/4013522.html

http://blog.csdn.net/eqera/article/details/8134986

✓   2015.7.10   週五
#import "CollectionHeader.h"

@implementation CollectionHeader

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        int screenWidth = [UIScreen mainScreen].bounds.size.width;
        _titleImageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, screenWidth,50)];
//上面這句話開始寫成了_titleImageButton = [[UIButton alloc]initWithFrame:self.frame];導致了header加載的位置錯誤❌,以後一定要注意子view的位置問題
        [self addSubview:_titleImageButton];
    }
    return self;
}
@end


//定義每個UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{

    return UIEdgeInsetsMake(0, 5, 5, 5);//用於設置section中所有cell圍起來佔的view和cell所在CollectionView的邊界在上,左,下,右四個方向上的距離。

}

 layout.minimumLineSpacing = paddingY;//這minimumLineSpacing設置cell縱向間距
    layout.minimumInteritemSpacing = 2;//這minimmInteritemSpacing設置cell橫向間距


dispatch_sync(dispatch_queue_create("com.liujie.ZMLIVE",NULL), ^{

        dispatch_async(dispatch_get_main_queue(), ^{
        });
    });

推送
http://blog.csdn.net/shenjie12345678/article/details/41120637

http://www.cocoachina.com/industry/20130321/5862.html

百度iOS推送配置步驟:
在進入證書界面後,在左邊的Identifiers選擇中選定App IDs,點右上角加號創建Appid ,爲遠程推送服務創建的App ID一定要是全稱,不能帶有*
真機調試用的APNs SSL證書:要在哪臺電腦上調試具有推送服務的App
這裏寫圖片描述
發佈程序用的APNs SSL證書:要在哪臺電腦上發佈具有推送服務的App
這裏寫圖片描述
最終得到2個APNs SSL證書 APNs Development iOS:真機調試用的證書 APNs Production iOS:發佈程序用的證書 
這裏寫圖片描述
證書配置03 – 生成描述文件 描述文件的作用是用來描述 哪臺設備要在哪臺電腦上調試哪個程序
這裏寫圖片描述

✓   2015.7.13   週一   請假


✓   2015.7.14   週二

百度推送
http://www.th7.cn/Program/IOS/201506/468069.shtml
http://samlee.gitcafe.io/jekyll/update/2015/06/11/samios.html

關於iOS Push Notification的響應問題
http://blog.sina.com.cn/s/blog_6fe6da830101mo4r.html

✓   2015.7.15   週三
#pragma -mark -functions

//獲取字符串的寬度
-(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
{
    CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX, height) lineBreakMode:NSLineBreakByWordWrapping];//此處的換行類型(lineBreakMode)可根據自己的實際情況進行設置
    return sizeToFit.width;
}
//獲得字符串的高度
-(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
{
    CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByCharWrapping];//此處的換行類型(lineBreakMode)可根據自己的實際情況進行設置
    return sizeToFit.height;
}

scrollView屬性
http://blog.csdn.net/aaajj/article/details/6872038
IOS中scrollsToTop問題小結
http://blog.csdn.net/enuola/article/details/32331933

XCode的 Stack Trace,調試時拋出異常,定位到某一行代碼
http://blog.csdn.net/enuola/article/details/17761017

全面理解iOS開發中的Scroll View
http://mobile.51cto.com/hot-430409.htm

  我們有一個拖動時frame不斷改變的視 圖。這達到了相同的效果,對嗎?如果我拖動我的手指到右邊,那麼拖動的同時我增大視圖的origin.x,瞧,這貨就是scroll view。
    當你設置它的contentOffset屬性時:它改變scroll view.bounds的origin。事實上,contentOffset甚至不是實際存在的。代碼看起來像這樣:
    1   - (void)setContentOffset:(CGPoint)offset  
    2   {  
    3       CGRect bounds = [self bounds];  
    4       bounds.origin = offset;  
    5       [self setBounds:bounds];  
    6   }
    scroll view的content size並不會改變其bounds的任何東西,所以這並不會影響scroll view如何組合自己的子視圖。反而,content size定義了可滾動區域。scroll view的默認content size爲{w:0,h:0}。既然沒有可滾動區域,用戶是不可以滾動的,但是scroll view仍然會顯示其bounds範圍內所有的子視圖。

當content size設置爲比bounds大的時候,用戶就可以滾動視圖了。你可以認爲scroll view的bounds爲可滾動區域上的一個窗口
用Content Insets對窗口稍作調整
contentInset屬性可以改變content offset的最大和最小值,這樣便可以滾動出可滾動區域。它的類型爲UIEdgeInsets,包含四個值: {top,left,bottom,right}。當你引進一個inset時,你改變了content offset的範圍。比如,設置content inset頂部值爲10,則允許content offset的y值達到10。這介紹了可滾動區域周圍的填充。
如果你通過滾動足夠多的距離初始化pull-to-refresh機制,因爲table view設置了content inset,這將允許content offset將refresh control彈回到可滾動區域。當刷新動作被初始化時,content inset已經被校正過,所以content offset的最小值包含了完整的refresh control。當刷新完成後,content inset恢復正常,content offset也跟着適應大小,這裏並不需要爲content size做數學計算。(這裏可能比較難理解,建議看看EGOTableViewPullRefresh這樣的類庫就應該明白了)
如何在自己的代碼中使用content inset?當鍵盤在屏幕上時,有一個很好的用途:你想要設置一個緊貼屏幕的用戶界面。當鍵盤出現在屏幕上時,你損失了幾百個像素的空間,鍵盤下面的東西全都被擋住了。
現在,scroll view的bounds並沒有改變,content size也並沒有改變(也不需要改變)。但是用戶不能滾動scroll view。考慮一下之前一個公式:content offset的最大值並不同於content size和bounds的大小。如果他們相等,現在content offset的最大值是{x:0,y:0}.
現在開始出絕招,將界面放入一個scroll view。scroll view的content size仍然和scroll view的bounds一樣大。當鍵盤出現在屏幕上時,你設置content inset的底部等於鍵盤的高度。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView1
{
    if ([scrollView1.restorationIdentifier isEqualToString:@"scrollView"])
    {
        NSLog(@"執行");
        if (scrollView1.contentOffset.y>3000) {
            NSLog(@"執行了");
            if (isFirstTopButton) {
                isFirstTopButton = NO;
                [self.view addSubview:topButton];
                NSLog(@"%lf    %lf",scrollView1.contentOffset.x,scrollView1.contentOffset.y);
            }
        }else{
            isFirstTopButton = YES;
            [topButton removeFromSuperview];
        }
    }
}
-(void)tapTopButton:(UIButton *)button
{
    //scrollView.contentOffset =CGPointMake(0, 0);
    //點擊回到頂部按鈕,滾回到屏幕開始位置。
    [scrollView scrollRectToVisible:CGRectMake(0, 0, screenWidth, screenHeight) animated:YES];
}
✓   2015.7.16   週四

分類推送

 NSMutableSet *tags = [[NSMutableSet alloc]init];//初始化tags、
if ([stringData isEqualToString: @"1"]) {
                 xiaoqu.text=@" 河北師大";
                 [self setXiaoquButtonSize];
                 SchoolId=@"1";
                 [tags addObject:SchoolId];
                 [APService setTags:tags callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];// 參數object是實現//tag返回的回調函數
- (void)tagsAliasCallback:(int)iResCode tags:(NSSet*)tags alias:(NSString*)alias {
    NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, tags , alias);
}

iOSApp發佈流程
http://www.macfans.org/thread-2370-1-1.html

iOS版本更新的App提交審覈發佈流程
http://www.2cto.com/kf/201502/378698.html

發佈流程:把App Id準備好了以後,在此Appid裏面將pushNotification用的開發推送證書和發佈推送證書弄好,弄證書的時候需要在鑰匙串請求request,request需要填開發者賬號的郵箱。然後弄發佈證書,發佈證書要對應Appid,然後弄發佈配置文件。
弄好了之後在Xcode中target和project中全都對應好發佈證書還有配置文件。然後在edit scheme中將Build configuration改爲release(這一步貌似不是必須的)。然後將真機拔掉,顯示iOS service,在product選項中選擇Archive(中文:檔案),然後沒錯誤進入Archives界面,點擊Submit,如果沒錯誤就成功。(錯誤通常是賬戶出現問題,解決方法:將沒用的賬戶刪了試試),之前在iTunes Connect中已經填的只剩構建版本了,刷新一下發現有了。提交併審覈就可以了。

http://jingyan.baidu.com/article/f25ef25477db8b482d1b8252.html

✓   2015.7.20   週一
//給tableView添加headerView
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView1;
    if(section==0) {
        headerView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 50)];
        [headerView1 setBackgroundColor:[UIColor orangeColor]];
        return headerView1;
    }
    return headerView1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}
✓   2015.7.22   週三


✓   2015.7.23   週四

第三方庫關於GridView實現網格視圖

✓   2015.7.24   週五

【譯】NSURLRequest的官方文檔
http://blog.sina.com.cn/s/blog_717fba110101dqzp.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章