iOS -- UI常用组件之. Button

来源:互联网 发布:淘宝上传图片不清楚 编辑:程序博客网 时间:2024/06/11 01:52

iOS – UI常用组件之. Button

// 常用设置UIButton *roundButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];//类型[roundButton setFrame:CGRectMake(60, 50, 200, 40)]; //大小[roundButton setTitle:@"Round Button" forState:UIControlStateNormal];//名称// 当buttonType为UIButtonTypeCustom时,[customButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];[customButton setBackgroundImage:[[UIImage imageNamed:@"whiteButton.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:20] forState:UIControlStateNormal]; //图片先拉伸再设置背景[customButton setBackgroundImage:[[UIImage imageNamed:@"back.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:20] forState:UIControlStateHighlighted];

// 封装Button(实例化、背景图片、弹簧动画的阻尼值、弹簧动画的速率)

//UIButton * btn1 = [self btnAnimateWithFrame:CGRectMake(LSCREENW/4-30, LSCREENH-80, 60, 60) imageName:@"img_wechat_logo" animateFrame:CGRectMake(LSCREENW/4-30, LSCREENH-130, 60, 60) delay:0.1];        btn1.tag=1;        [btn1 addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];//-(UIButton *)btnAnimateWithFrame:(CGRect)frame imageName:(NSString *)imageName animateFrame:(CGRect)aniFrame delay:(CGFloat)delay{    UIButton * btn =[[UIButton alloc]init];    btn.frame =frame;    [btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];    [self  addSubview:btn];    [UIView animateWithDuration:1 delay:delay usingSpringWithDamping:0.3 initialSpringVelocity:0.2 options:UIViewAnimationOptionAllowUserInteraction animations:^{        btn.frame  = aniFrame;    } completion:^(BOOL finished) {    }];    return btn;    //usingSpringWithDamping :弹簧动画的阻尼值,也就是相当于摩擦力的大小,该属性的值从0.0到1.0之间,越靠近0,阻尼越小,弹动的幅度越大,反之阻尼越大,弹动的幅度越小,如果大道一定程度,会出现弹不动的情况。    //initialSpringVelocity :弹簧动画的速率,或者说是动力。值越小弹簧的动力越小,弹簧拉伸的幅度越小,反之动力越大,弹簧拉伸的幅度越大。这里需要注意的是,如果设置为0,表示忽略该属性,由动画持续时间和阻尼计算动画的效果。}
0 0