关于stepper,文字属性NSAttributeString

主要是利用attributeString,mutableCopy一个,然后对其更改其属性,再赋回原来的值;

Stepper几个知识点:
1.value
1.maxinumValue

NSRange,注意: [range.location != NSNotFound;

Screen Shot 2013-05-22 at 下午11.23.32

- (IBAction)underLine {
    NSRange range = [[self.wordsLabel.attributedText string] rangeOfString:[self selected]];
    
    NSMutableAttributedString *mat = [self.wordsLabel.attributedText mutableCopy];
    
    [mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:range];
    
    self.wordsLabel.attributedText = mat;
}


-(NSArray *)WordsList
{
    NSArray *WordsList = [[self.wordsLabel.attributedText string] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
    if ([WordsList count]) {
        return WordsList;
    }else{
        return @[@" "];
    }
}

-(NSString *)selected
{
    return [self WordsList][(int)self.stepper.value];
}
- (IBAction)updateSelectedWords {
    self.stepper.maximumValue = [[self WordsList] count]-1;
    self.label.text = [self selected];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self updateSelectedWords];
	// Do any additional setup after loading the view, typically from a nib.
}



-(void)addSelectedWordsAttribute:(NSDictionary *)attribute
{
    NSRange range = [[self.wordsLabel.attributedText string] rangeOfString:[self selected]];
    
    [self addwordslabelAttribute:attribute range:range];
    
}
-(void)addwordslabelAttribute:(NSDictionary *)attribute range:(NSRange)range


{
    if (range.location != NSNotFound) {
        NSMutableAttributedString *mat = [self.wordsLabel.attributedText mutableCopy];
        
        [mat addAttributes:attribute range:range];
        
        self.wordsLabel.attributedText = mat;
    }

}



- (IBAction)underLine {
    [self addSelectedWordsAttribute:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)}];
    }

- (IBAction)ununderLine {
    [self addSelectedWordsAttribute:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)}];
}


- (IBAction)changeColor:(UIButton *)sender {
    [self addSelectedWordsAttribute:@{NSForegroundColorAttributeName: sender.backgroundColor}];
}

稳健不忘发展,发展不忘稳健

不投机取巧
解决困难的快乐

欧洲很多国家失业率很大,中国的货物物美价廉
工厂赚很少,大部分利润都在进口商

国内企业家要找自己的市场,marketing,对市场的把握要靠自己建立起来;自己有自己的市场;

做任何事情之前,都要先考虑市场;

获取最新的信息,获取所在行业的最全面,最好的信息,在此基础上做决定;
不仅仅是进取,还要考虑失败的情况,有所备;

成功后,很多事都可以做,特别是在帮助很多无助的人;

不管在东方也好,西方也好,都有一个核心的业务;
中高级的员工,退休了,不仅仅自己老有所养,还能..
对待员工,薪水高,但是绝不允许贪污;

如一个经理:
对公司对工作有贡献
忠于公司,希望长期服务公司
人格不错

对员工:
前途有保障,收入不错
好的前途,好的待遇
在有好制度前提下,信任他;

忙录的两天,累并充实着

这两天的日子跟原来一直坐在办公室有着很大的区别,很忙录,弄得很累,但却感觉充满能量,相当充实..

做事还是胆小,不够自信!!!!
英语还是不够用.

ios开发的学习还是要继续, 现在有一定的基础,最主要的还是要找个简单的项目来练练手,给自己点信心;

IOS应用开发基础:iCloud数据存储与读取

1.removeItemAtURL删除本地文件document。
2。创建子目录来存储文件。

    self.ubiquityURL = [[fMgr URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:@"Documents"];

3。创建文档使用self.ubiquityURL目录
4。在iCloud中使用set谓词document.doc搜索:[NSpredicate predicateWithFormat:@“%K like 'document.doc'”,NSMetadataItemFSNameKey];

tttttttttttttttt4

 

NSMetaDataItemFSSizeKey, NSMetaDataItemFSCreationDataKey, NSMetaDataItemFSContentChangeDataKey

5.Then设置搜索范围NSMetaDataQueryUbiquitysDocumentsScope的;

  [self.metaDataQuery setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];

PS:另外一个搜索数据:NSMetaDataQueryUbiquitysDataScope另一个范围;
6。开始查询[self.metaDataQuery startQuery];
7。设置一个通知,当搜索查询完成:NSMetaDataQueryDidfinishGatheringNotification

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(metaDataQueryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:self.metaDataQuery];

ggggggggggggggggg

8.用metaDataQueryDidfinishGather继续
a. NSMetadataQuery *query = [notificaiton object];
b.在查询中停止通知 remove the notification from query;
c。停止查询; stop query;

9。得到的结果对象从[查询结果] got the result object from [query result]

        NSArray *results = [[NSArray alloc] initWithArray:[query results] ];

10. check if the [result count] == 1. if yes, got the ubiquityURL and document.doc using:
The important thing is if there’s only search a specific file, then the first file is what we need.

self.ubiquityURL = [result[0] valueForAttribute:NSMetaDataItemURLKey];
           self.document = [[BKDocument alloc] initWithFileURL:self.ubiquityURL];
[self.document openWithCompletionHandler:^(BOOL success) {
            if (success) {
                self.textView.text = self.document.userText;
            }else{
                NSLog(@"Faild to open");
            }
        }]

11.if there’s not any result, then create it using saveToURL:
UIDocumentSaveForOverWriting,UIDocumentSaveForCreating
12. Finally Click the Save button to save text to document;

//
//  BKViewController.h
//  BKDocument
//
//  Created by xushao on 13-4-5.
//  Copyright (c) 2013年 xushao. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "BKDocument.h"

@interface BKViewController : UIViewController
@property(nonatomic, strong)BKDocument *document;
@property(nonatomic, strong) NSURL *documentURL;

@property(nonatomic, strong)NSMetadataQuery *metaDataQuery;

@property(nonatomic, strong)NSURL *ubiquityURL;
@property (strong, nonatomic) IBOutlet UITextView *textView;

- (IBAction)savebutton:(id)sender;

@end
//
//  BKViewController.m
//  BKDocument
//
//  Created by xushao on 13-4-5.
//  Copyright (c) 2013年 xushao. All rights reserved.
//

#import "BKViewController.h"

@interface BKViewController ()

@end

@implementation BKViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *dataPath = filePath[0];

    NSString *path = [[NSString alloc] stringByAppendingPathComponent:dataPath];

    NSFileManager *fMgr = [NSFileManager defaultManager];
    NSError *error;
    [fMgr removeItemAtPath:path error:&error];

    self.ubiquityURL = [[fMgr URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:@"Documents"];

    if ([fMgr fileExistsAtPath:[self.ubiquityURL path]]==NO) {
        [fMgr createDirectoryAtURL:self.ubiquityURL withIntermediateDirectories:YES attributes:nil error:nil];
    }
    self.ubiquityURL = [self.ubiquityURL URLByAppendingPathComponent:@"document.doc"];

        self.metaDataQuery = [[NSMetadataQuery alloc] init];

    [self.metaDataQuery setPredicate:[NSPredicate predicateWithFormat:@"%K like 'document.doc'",NSMetadataItemFSNameKey]];
    [self.metaDataQuery setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
    [self.metaDataQuery startQuery];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(metaDataQueryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:self.metaDataQuery];
	// Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

                        -(void)metaDataQueryDidFinishGathering:(NSNotification *)notificaiton
    {
        NSMetadataQuery *query = [notificaiton object];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:query];

        [query stopQuery];

        NSArray *results = [[NSArray alloc] initWithArray:[query results] ];
        if ([results count]==1) {
            self.ubiquityURL = [results[0] valueForAttribute:NSMetadataItemURLKey];

            self.document = [[BKDocument alloc] initWithFileURL:self.ubiquityURL];
        [self.document openWithCompletionHandler:^(BOOL success) {
            if (success) {
                self.textView.text = self.document.userText;
            }else{
                NSLog(@"Faild to open");
            }
        }];
        }else{
            self.document = [[BKDocument alloc] init];

            [self.document saveToURL:self.ubiquityURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
                if (success) {
                    NSLog(@"Create Success");
                }else{
                    NSLog(@"Couldn't create file");
                }
            }];

        }

                        }
- (IBAction)savebutton:(id)sender {

    self.document.userText = self.textView.text;

    [self.document saveToURL:self.ubiquityURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success) {
        if (success) {
            NSLog(@"Over writing success");
        }else{
            NSLog(@"Over writing failed");
        }
    }];
}
@end

Iphone开发基础与例子2:Machimo卡牌游戏

利用上一文章:IOS6开发基础与例子Iphone开发  中的:Cards, PlayingCards, Deck, PlayingCardsDeck 等数据model;

PS:option+shif+k 是苹果的logo快捷键

利用button 的default及selected作为扑克牌的正反两面;

 

@interface BKViewController ()
@property (weak, nonatomic) IBOutlet UILabel *flipLabel;
@property (nonatomic)int flipCount;
@property(nonatomic, strong)IBOutletCollection(UIButton)NSArray *cardButtons;
@end

@implementation BKViewController

-(void)setFlipCount:(int)flipCount{
    _flipCount = flipCount;
    
    self.flipLabel.text =[NSString stringWithFormat:@"%d",self.flipCount];
}

- (IBAction)flipCard:(UIButton *)sender {
    sender.selected =! sender.isSelected;
    self.flipCount++;
    
}


-(BKDeck *)deck
- (IBAction)flipCard:(UIButton *)sender {

    sender.selected = ! sender.isSelected;
    self.flipCount++;
    self.flipLabel.text = [[NSString alloc] initWithFormat:@"The Flip is %d", self.flipCount];
}

{   
    if(!_deck)_deck = [[BKPlayingCardDeck alloc] init];//注意这里是为什么??Lazy instantiation.当对一个Array进行插入调用时,该array必须不能为nil;
    return _deck;
}


-(void)setCarButtons:(NSArray *)carButtons
{
    _carButtons = carButtons;//注:当用setter时,这行是必须的;
    
    for( UIButton *carButton in self.carButtons){
        BKCard *card = [self.deck drawRamdonCard];
        
        [carButton setTitle:card.contents forState:UIControlStateSelected];
    }
}

注意flibCount的定义:@property (nonatomic)int flipCount;

如何学习iphone开发

这不是一篇教你如何学习iphone开发的文章,而是探讨如何更有效的学习iphone开发,希望广大开发者也分享下自己的经验;

我先说说我自己的经历经验吧,目前学习开发已经快一年了,原先只有一点C的基础,英文较好,能看懂英文文档,听懂英文视频,所以我的学习材料全部是英文的,首先是早期在amazon.com 的买了几本object-c及ios开发的书;其实也并非特意用英文资料,只是国内的ios开发资料太旧了,根本找不到最近的,例如刚开始学时,中文的只有 ios5,而苹果的每个版变化还是蛮大的,所以如果英语还过得去,用英语教程是最省事的;

objective-C 2.0 Essential
Iphone ios 6 development Essentials
Beginning iOS 6 Development Exploring the iOS SDK

学完了这几本书后,基本就知识就有了,可是只是刚进门而已,刚好就在上个月,苹果itunes上出现了哈佛公开课ios开发的最新教程,ios6视频教程,把我高兴得,于是就反复看,反复听,反复练习

目前就学习到这里,书跟视频各有专注,虽然说现在 可以去开发一些简单的应用,但感觉没打好基础就去折腾,会得不尝失,所以还是把基础打好再说;

同时,希望能跟更多这行业的朋友交流交流!

QQ群:92306165

IOS6开发基础与例子Iphone开发

本文为记录要点文章,例子详细教程请参考:哈佛ios6视频教程:https://itunes.apple.com/cn/course/coding-together-developing/id593208016

 

1.card包括:

@property(nonatomic, strong)NSString *content;
@property(nonatomic)Bool faceUP;
@property(nonatomic)BOOL unplayable;
-(int)match:(NSArray *)otherCards;

2.playingCard:

@property(nonatomic,strong)NSString *suit;
@property(nonatomic)NSUinteger rank;
+(NSArray *)validSuit;
+(NSUinteger)maxRank;

3.注意Class方法与instant 方法调用区别:
4.Setter 和 Getter

@synthesize suit = _suit;
-(void)setSuit:(NSString *)suit{
    if ([[BPlayingCard validSuit] containsObject:suit]) {
        _suit = suit;
    }}

-(NSString *)suit{
    return _suit ? _suit : @"?";
}

5.private:
@property(nonatomic, strong)NSMutableArray *cards;

MutableArray的一般方法及作用:

   - (void)addObject:(id)anObject;  
     - (void)insertObject:(id)anObject atIndex:(int)index;  
   - (void)removeObjectAtIndex:(int)index; 
Usually created with  [[NSMutableArray alloc] init]

6.Array有以下注意点:
用for (TGGCards *card in otherCards)等循环可获取到项目中的每个object;
lazy 初始化Array:

如:

-(NSMutableArray *)cards
{
if(!_cards) _cards =  [[NSMutableArray alloc] init];
return _cards;
}

7.TGGDeck:

8.TGGPlayingCardDeck:

-(id)init{
    
    self = [super init];
    
    if (self) {
        for( NSString *suit in [BPlayingCard validSuit])
            for (NSUInteger rank=1; rank<=[BPlayingCard maxRank]; rank++) {
                BPlayingCard *card = [[BPlayingCard alloc] init ];
                
                card.rank = rank;
                card.suit = suit;
                
                [self addCard:card atTop:YES ];
            }
        
        
    }
    
    
return self;

}

TooGooGoo又回来了

5年前注册了这个域名,当时做的第一个站,其后这个网站的发展真的是一波三折,不断的变化,不断的折腾,从中文站到英文站,再从英文站到中文站,接着又从博客改成商城,或者商城改成博客,再或者就进行301等等等等;

5年过去了,这个站又回到了原点,由于折腾得太多,在GG的印象估计不太好,后来一直就没有了排名;今天再次换成中文的博客,这个站的变化,在某些方面又映射着我的职业道路的变化,这期间做了几百几千个网站,不断的有新站站起来,又不断的有旧站倒下去,好的坏的,从来没有在我的人生道路里面停留太久,因为这些站从一开始就背负着功利的目标,只为了赚取短期的利益,一旦失去了这个功能,那么网站就没有存在的理由;

我不希望我5年或者10年后依旧写这种无奈自嘲的文章,这五年来个人感觉没有太大的成长,除了收获了一些金钱,还有一些折腾的技巧,就没有什么值得骄傲的成就了;这不是我想要的,但有时候生活就是这么现实,你首先得解决生计问题,其次才去考虑理想,理想跟现实常常是矛盾的,例如你的理想是做一个对社会有价值的人,社会因为你的存在而变得美好一点点……省略掉,这个话题太长了;

或者根本就没有所谓的理想跟现实之分,存在即合理,你做出选择的同时也应选择接受及相信你的选择,跟着你的心走,怎么舒服怎么走。
献丑了,欢迎交流!