常用代码小记

1.UILabel  换行

1     versionLabel.lineBreakMode = UILineBreakModeWordWrap;
3     versionLabel.numberOfLines = 0;

2.UILabel  阴影

1   tipLabel.shadowColor = [UIColorwhiteColor];
2   tipLabel.shadowOffset = CGSizeMake(1.0, 1.0);

3.自定义 View 实现drawRect方法

@interface CustomView :UIView
@end
@implementation CustomView
- (void)drawRect:(CGRect)rect
{
    //画长方形
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(ctx, [RGBCOLOR(213, 213, 213) CGColor]);
    CGContextSetLineWidth(ctx, 1.0);
    CGPoint poins[] = {CGPointMake(0, 0),CGPointMake(280, 0),CGPointMake(280, 40),CGPointMake(0, 40)};
    CGContextAddLines(ctx,poins,4);
    CGContextClosePath(ctx);
    CGContextStrokePath(ctx);
    //画线
    CGContextMoveToPoint(ctx, 195, 0);
    CGContextAddLineToPoint(ctx, 195, 40);
    CGContextSetLineWidth(ctx, 1.0);
    CGContextStrokePath(ctx);
}
@end

4.复制到剪贴板

1  UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
2  pasteboard.string = qqLabel.text;

5.键盘事件

1  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
2     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

 实现方法:

#pragma mark - key board notice
-(void)keyboardWillShow:(NSNotification*)note
{
    [UIView animateWithDuration:0.3 animations:^(void)
     {
         CGRect r = CGRectZero;
         [[note.userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"] getValue:&r];
         CGRect rect = contentView.frame;
         rect.size.height = 460-70-r.size.height;
         contentView.frame = rect;

        }];
    
}

-(void)keyboardWillHide:(NSNotification*)note
{
    [UIView animateWithDuration:0.3 animations:^(void)
     {
         CGRect rect = contentView.frame;
         rect.size.height = 174;
         contentView.frame = rect;       
     }];
    
}

 

 

转载于:https://www.cnblogs.com/smallyin00/archive/2012/10/10/2718399.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值