杂锦

来源:互联网 发布:营销型企业网站源码 编辑:程序博客网 时间:2024/06/04 01:11

NSuserDefaults 存储setObject

NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];

NSString *mainUrl = [NSString stringWithFormat:@"http://emsp.ip165.com/lst/port/"];

[accountDefaults setObject:mainUrl forKey:MAIN_URL_MRK];



_progressHUD = [[MBProgressHUD allocinitWithView:self.view];

    [self.view addSubview:_progressHUD];;

    _progressHUD.labelText = @"数据加载中...";

    [_progressHUD show:YES];



self.title = @"借款到期"; 在VIewController中可以直接用self.title导航栏上的标题

alpha --------- entire View

opaque ---------- partially transparent 默认为NO


用push和pop定义画子线路

- (void)drawGreenCircle:(CGContextRef)cref

{

    UIGraphicsPushContext(cref);

    [[UIColor redColorsetFill];

    UIGraphicsPopContext();

}

- (void)drawRect:(CGRect)rect

{

    CGContextRef context = UIGraphicsGetCurrentContext();

    [[UIColor greenColorsetFill];

    [self drawGreenCircle:context];

}


UIFont --- systemFontSize boldSystemFontOfSize italicSystemFontOfSize

                 familyNames fontNamesForFamilyName



UILabel作为子视图在UIView上画文字时用NSAttributedString

    NSAttributedString *text = [[NSAttributedString allocinit];

    [text drawAtPoint:<#(CGPoint)#>];

    CGSize textSize = [text size];//text占用的空间

NSAttributedString

    不是继承于NSString 用到NSString的方法时需要转换

    - (void) attributesAtIndex:(NSInteger)index effectiveRange:(NSRangePointer)range 

NSMutableAttributedString

    - (void) addAttributes:(NSDictionary *)attributes range:(NSRange)range

    - (void) setAttributes...........

    - (void) removeAttribute:.........


@{NSFontAttributeName : [UIFont systemFontOfSize:24],NSForegroundColorAttributeName : [UIColor greenColor],NSStrokeWidthAttributeName : @-5,NSStrokeColorAttributeName : [UIColor redColor], NSUnderlineStyleAttributeName :@(NSUnderlineStyleNone),NSBackgroundColorAttributeName : [[UIColor yellowColorcolorWithAlphaComponent:0.3]};//减号代表strokefill 加好代表stroke(outline)



用UIBezierPath画线

UIBezierPath *path = [[UIBezierPath allocinit];

    path.lineWidth = 2.0;

    [path moveToPoint:CGPointMake(7510)];

    [path addLineToPoint:CGPointMake(160150)];

    [path addLineToPoint:CGPointMake(10150)];

    [path closePath];

    [[UIColor greenColorsetFill];

    [[UIColor redColorsetStroke];

    [path stroke];

    [path fill];

    

    UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:<#(CGRect)#> cornerRadius:<#(CGFloat)#>];//圆形

    UIBezierPath *oval = [UIBezierPath bezierPathWithOvalInRect:<#(CGRect)#>];//椭圆形

    [roundedRect addClip];//剪切

    [roundedRect stroke];

    [oval fill];


用CoreGraphics配合touchesBegin画线

永远不要调用drawRect方法用setNeedsDisplay或setNeedsDisplayInRect

- (void)drawRect:(CGRect)rect

{

    for (int i = 0; i < allLineArray.count; i++)//存储画笔的总条数

    {

        CGContextRef context = UIGraphicsGetCurrentContext(); //获取这个画图环境

        NSMutableArray *lineArray = [allLineArray objectAtIndex:i];//获取当前画笔(即该画笔存储颜色和画笔宽度的数组)

        

        CGFloat width = [[lineArray objectAtIndex:1floatValue];

        CGContextSetLineWidth(context, width);

        

        UIColor *color = [lineArray objectAtIndex:0];

        CGContextSetStrokeColorWithColor(context,color.CGColor); //注意后面的color是要加上.CGColor

        

        for (int j = 2; j < [lineArray count] - 1; j++)//存储画笔条的点数

        {

            //line里面取出开始和结尾的点并转换为坐标

            NSValue *value = [lineArray objectAtIndex:j];

            CGPoint point = [value CGPointValue];

            NSValue *value1 = [lineArray objectAtIndex:j+1];

            CGPoint point1 = [value1 CGPointValue];

            //坐标在图画中的开始点和结束点之间添加直线

            CGContextMoveToPoint(context, point.x, point.y);

            CGContextAddLineToPoint(context, point1.x, point1.y);

        }

        

        //沿着上面设置好的画图轨迹喷涂

        CGContextStrokePath(context);

    }

}

//一个UITouch对象表示一个触摸,一个UIEvent对象表示一个事件

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    //苹果假设触摸以数组存储并给了UITouch 然后转换为CGPoint并把触摸变为了点且传给了一个数组

    UITouch *touch = [touches anyObject];  //event中包括了所有的触摸对象

    CGPoint point = [touch locationInView:self];

    //把这个点加到总画线数组中的第一个数组中 并将第一个数组加到总画线数组

    NSMutableArray *lineArrayFirst = [[NSMutableArray allocinitWithObjects:colorChange,[NSNumber numberWithFloat:pencilWidth],[NSValue valueWithCGPoint:point],nil];

    [allLineArray addObject:lineArrayFirst];

    [lineArrayFirst release];

    //重绘视图,会调用drawRect方法

    [self setNeedsDisplay];

}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    CGPoint point = [touch locationInView:self];

    //取到总画线数组中的最后一条画线

    NSMutableArray *lineArrayLast = [allLineArray lastObject];

    NSValue *value = [NSValue valueWithCGPoint:point];

    [lineArrayLast addObject:value];

    [self setNeedsDisplay];

}


画图UIImageView中的UIImage或者CGContext方法

UIGraphicsBeginImageContext(<#CGSize size#>);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    [image drawAtPoint:<#(CGPoint)#>];

    [image drawInRect:<#(CGRect)#>];

    [image drawAsPatternInRect:<#(CGRect)#>];

    

    //获取图片为data

    NSData *jpgData = UIImageJPEGRepresentation(<#UIImage *image#>, <#CGFloat compressionQuality#>);

    NSData *pngData = UIImagePNGRepresentation(<#UIImage *image#>); 


UIViewContentMode属性可以move Bit of drawing to location 

UIViewContentModeScale属性可以stretch the bits of your drawing

UIViewContentModeRedraw属性可以重新画


改变了bounds后要你的子视图也需要改变 调用viewWillLayoutSubviews方法

    

视图的中心点位置是bounds而不是frame因为视图可以旋转之后两者是不同的

(bounds.size.width/2 + bounds.origin.x,bounds.size.height/2+bounds.origin.y)



功能 接口 类封装 -- 封装类
类 属性 实例以什么开头 -- 小组命名规范
整体流程时间把控 两周时间 -- 时间把控
组员模块分工 -- 模块分工

ddmenu 左右滑页

1 封装后的方法需要在viewDidLoad中调用 _initTableViewController 在BasicTabBarController中


plist文件的深入理解 再去值的时候要弄清楚存的是什么
下拉被挡住就直接改frame得大小
if (self.easySearch == YES) 不是一个=号 不然不会 [self.tableview reloadData];


今天解决了一个大难题 tableFooterView可以直接添加button 直接赋值button的坐标会变形 加上一个View给其设置坐标好了将button贴到view上再让view为FooterView

发现viewDidLoad和ViewDidAppear的关系层次没有弄明白 加载到后者才会消失, 也就是说加载完了不等于显示完了显示是在加在后面的    一次性初始化的数据用前者,当view将被显示的时候,要整理的数据放后者.说的再明白点儿,前一个,只执行一次,后一个,每次切换到的时候,都执行 有时候会在页面切换的时候出现白边 注意viewWillAppear都只是相对自己当前的VC来说的不是即将推送的VC所以设置的时候推向谁出现白边应该去要推谁的那个后者VC中设置viewDidAppear让其才实现隐藏

其实经过我最后的确定是要自定义的要通过遍历隐藏 系统本身的也会存在不会消失 这时候你可以在push的时候之前实例化推送VC的时候对应的就设置其hiddenWhenPush属性为yes;就可以完美解除问题

 [shareWithMyFriends showInView:[[UIApplication sharedApplication] keyWindow]];这个可以解决最后的取消button不响应的问题 且不会像showInToolBar那样使actionSheet颜色加深 非常好

_characterRemainNumberLabel.text = [[NSString alloc] initWithFormat:@"您还能输入%d个字",150 - _textAlreadyExist]; //这里需要附两遍值在外面要写一遍才能加载的时候出现文字 这里在代理方法中又要写一遍让其能够变化 虽然都是全局变量但这里要写两遍 其实也不是特别清楚

自定义UIAlertView [self dismissWithClickedButtonIndex:2 animated:YES];
- (void)layoutSubviews
- (void)drawRect:(CGRect)rect
- (void)show 后面两个方法基本一样 但都要写 前一个是用来隐藏系统的控件的

     发现一个问题直接在VC里添加TableviewController后加入self.view(不实现代理方法 那些什么height和cell) 要比封装一个        UITableViewController类自身实现了代理方法少显示有缺口地方 封装以后再添加好像没有 
默认情况下使用
UITableViewController创建的tableView是充满全屏的,如果需要用到tableView是不充满全屏的话,我们应该使用UIViewController自己创建和维护tableView  
   UITableViewController默认的会在viewWillAppear的时候,清空所有选中cell,我们可以通过设置self.clearsSelectionOnViewWillAppear = NO,来禁用该功能,并在viewDidAppear中调用UIScrollViewflashScrollIndicators方法让滚动条闪动一次,从而提示用户该控件是可以滑动的。 
    通过从UITableViewCell中派生一个类,可以更深度的定制一个cell,可以指定cell在进入edit模式的时候如何相应等等。最简单的实现方式就是将所有要绘制的内容放到一个定制的subView中,并且重载该subViewdrawRect方法直接把要显示的内容绘制出来(这样可以避免subView过多导致的性能瓶颈),最后再将该subView添加到cell派生类中的contentView中即可。但是这样定制的cell需要注意在数据改变的时候,通过手动调用该subViewsetNeedDisplay方法来刷新界面
   UITableView提供了一个批量操作的特性,这个功能在一次进行多个row或者scetion的删除,插入,获取更新多个cell内容的时候特别好用。所有的批量操作需要包含在beginUpdatesendUpdates块中,否则会出现异常。

参数传过来了(如果是NSSring的等一定要在接受的时候将前面申请的全局变量初始化不然也有可能导致后面的东西即使传过来了也用不了),但是通过方法传递的在viewDidLoad后面才执行方法 可是我发送异步请求又是在ViewDidLoad里面 这样就导致传过来的参数不能为我的请求所用 所以即使是全局变量也不行 这时候我就在传递方法里面重新调用一次[self viewDidLoad];则数据就传到viewdidload中了请求就有数据了 哈哈 是不是很神奇参考更多里面的求职指导的详细内容 有时候可以将要用的地方的语句直接拷贝到下面传值方法中也行但复杂的话就要调用整个方法了比如ViewDidLoad

如果在uiwebView中直接访问网址默认是按回车键 当然在viewDidLoad不需要(当然网址要正确)另外网址就是要加上http://不然webView是不能够识别的
NSURL *urlString = [[NSURL alloc] initWithString:@"http://wap.zhaopin.com"];

在headerView上添加了button 当我想获取所在的section值的时候由于不是row或行因此无法通过系统选中谁而得知是谁 因而要用我们自己的方法就是button有tag值变化可以记录下来如果是手动添加则手动设置 如果是自动添加则设设置一个静态变量初试为0然后让其后++ 用他的时候直接把button的tag值当做参数传过去就行了

transition.type = @"rippleEffect" 动画效果
【//@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; /* 动画的开始与结束的快慢*/
transition.subtype = kCATransitionFromRight;   /* 动画方向*/

1、调用 电话phone[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://4008008288"]];

2、调用自带 浏览器 safari[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.abt.com"]];

3、调用 自带mail[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@abt.com"]];

4、调用 SMS[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];

5,跳转到系统设置相关界面[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];


选中和非选中图片设置

[checkbox setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal];
  [checkbox setImage:[UIImage imageNamed:@"checkbox_on.png"] forState:UIControlStateSelected];

[[UIApplication sharedApplication] setIdleTimerDisabled:YES]; 不自动黑屏的方法

获取设备信息
[[UIDevice currentDevice] systemName];
[[UIDevice currentDevice] systemVersion];//os version
[[UIDevice currentDevice] uniqueIdentifier];
[[UIDevice currentDevice] model];
[[UIDevice currentDevice] name];

子类不仅得到了父类的方法的实现,而且还可以覆盖父类方法的实现,即重写方法。注意:OC中没有方法重载的概念。重载:指允许存在多个同名函数,而这些函数的参数不同

数组的初始化位置很重要 比如薪酬查询中的checkMark的多行选中加入到数组中在cell中判断是否包含选中组并设置回来 在did和cellForRow中初始化就不行 在viewDidLoad中就可以了

从前往后传值和从后往前传值的区别是后者包括前者传值过程,后面需要把接收到的值赋值给前面类的实例化出来的变量然后在本类中传值过去在前面类去实现 如果你直接在后面类中引入头文件使用前面类的方法后传值不会对前面类做出影响 虽然值可以传递过去 只有你包含从前往后的过程再从后往前传才能完美参考薪酬查询地区实现

用单例传值时需要点击后面去才会赋值到单例属性 而程序启动时就会调用一次viewWillAppear即使有东西也不会显示没有也不要紧因为后面接着走viewDidLoad以后面为准,单页面切换时又会调用appear不会调用load所以在viewWillAppear中做一个判断就行 如果单例属性为空则显示什么以保证不会因为选了一个行业回来传回行业值但企业性质等行变成空白了


自动消失UIAlertView的定时器的方法
- (void) performDismiss:(NSTimer *)timer
{
    [view1 dismissWithClickedButtonIndex:0 animated:YES];
}
  1. [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];  
  2. [Alert show];  

tableView中有rowHeight属性

self.isSecondView = !self.isSecondView;这种赋值方法值得学习 可以简化判断如果后面的为真则前面的属性为假 后面为假则前面为真

不要轻易用 == it means that two pointers are equal use isEqualToString instead

self.cards[index]  这个写法相当于用属性调用了数组的objectAtIndexedSubscript:index (cards是一个可变数组)
@[] 相当于[[NSArray allo]initWithObjects....]
@"" 相当于[[NSString alloc]]init]

如果自己改写了set和get方法 则需要synthesize一下 依然还是 属性=_属性;

array的初始化地方很关键 最好在一开始的地方就初始化 以免后面用到是空得不能操作了

[super init] 父类调用init 发送init消息到super
初始化器中把[super init]赋值给了self 如果self为空即[super init]返回为空的话既不能初始化本类 所以需要在下面进行判断if(self)

在类方法中调用同文件中其它类方法的时候用self
类方法自身在被调用时用本类调用

alt + shift + k 出现?0?0的标志哦
alt + shift + t 出现特殊符号标志(xCode中)

@property (weak,nonatomic) IBOutlet UILabel *label;在storyboard上的MVC's的VIew已经是strong了 所以在把空间outlet拖到controller上的时候不需要再strong了而是weak 当然若果希望离开view了还能保持指针指向它则可灵活改为strong 
@property (strong,nonatomic)  IBOutletConnection (UIButton)NSArray *array;但如果MVC's View上有一个outlet属性是array的时候包含一群button的时候 view指向那些buttons 而不是array本身 所以array需要strong

@interface 类目和延展可以选择 前面的是要公开后面的是私有只写在.m中
而且同样的属性可以在公开和私有中有不同的特点比如在外面是(nonatomic,readOnly) int a;在私有中可以改为 (nonatomic) int a;

在自定义的alertView中添加通知时我选择在show上 而不是在layoutsubviews这个方法了在那里面不能接受的



UITableView上监听手势并添加到tableView上的可以通过手势代理方法获取 判断是不是点击的UITableViewCellContentView解决了

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{

    NSLog(@"%@",NSStringFromClass([touch.view class]));

    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"])

    {

        return NO;

    }

    return YES;

}



写类最好数据和控制器分开比如UITableView就不会有控件重叠的的现象或者数据显示混乱的现象

floor()是向下舍入 123.54 ---- 123.00

ceil()是向上舍入 123.54--- 124.00


单例最新的写法
+ (id)sharedManager {
static MyManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
someProperty = [[NSString alloc] initWithString:@"Default Property Value"];
}
return self;
}

非ARC代码的单例
虽然我并不那么推荐,但是如果你要使用非ARC环境的话,你应该使用以下代码:
  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#import "MyManager.h"
static MyManager *sharedMyManager = nil;
@implementation MyManager
@synthesize someProperty;
#pragma mark Singleton Methods
+ (id)sharedManager {
@synchronized(self) {
if(sharedMyManager == nil)
sharedMyManager = [[super allocWithZone:NULL] init];
}
return sharedMyManager;
}
+ (id)allocWithZone:(NSZone *)zone {
return [[self sharedManager] retain];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (id)retain {
return self;
}
- (unsigned)retainCount {
return UINT_MAX; // 表示该对象永远不应被释放
}
- (oneway void)release {
// 从不释放
}
- (id)autorelease {
return self;
}
- (id)init {
if (self = [super init]) {
someProperty = [[NSString alloc] initWithString:@"Default Property Value"];
}
return self;
}
- (void)dealloc {
// 从不调用该方法
[someProperty release];
[super dealloc];
}
@end