自定义背景颜色的设置

来源:互联网 发布:零基础学c语言看什么书 编辑:程序博客网 时间:2024/04/30 07:36

#define kDEFAULT_DATE_TIME_FORMAT (@"yyyy-MM-dd")



-(void)buildLayout{

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(100, 30,150, 40)];

    label.text=@"设置背景颜色";

    label.backgroundColor=[UIColor clearColor];

    [self.view addSubview:label];

    [label release];

    

    UISlider *slider=[[UISlider alloc]initWithFrame:CGRectMake(30,8025030)];

    [slider addTarget:self action:@selector(colorchange:)forControlEvents:UIControlEventValueChanged];

    slider.minimumValue=50;

    slider.maximumValue=255;

    slider.value=128;

    slider.tag=100;

    [self.view addSubview:slider];

    [slider release];

    

    UIButton *but=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    but.frame=CGRectMake(10013010030);

    [but setTitle:@"重置" forState:UIControlStateNormal];

    [but addTarget:self action:@selector(btnclick)forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:but];



-(void)colorchange:(id)sender{

    UISlider *slider=sender;

    UIColor *color=[UIColor colorWithRed:slider.value/20green:slider.value/100 blue:slider.value/300 alpha:1.0];

    self.view.backgroundColor=color;

    [[NSNotificationCenterdefaultCenter]postNotificationName:@"bgcolor" object:[UIColorcolorWithRed:slider.value/20 green:slider.value/100blue:slider.value/300 alpha:1.0]];

}

-(void)changebg:(NSNotification *)bg{

    AppDelegate *nowdelegate=[UIApplicationsharedApplication].delegate;

    nowdelegate.window.backgroundColor=[UIColorcolorWithPatternImage:[UIImage imageNamed:bg.object]];

}

-(NSString *)whatjieqiis{

    NSString *dpath=[[NSBundle mainBundle]pathForResource:@"jpdata"ofType:@"plist"];

    NSMutableArray *jqbiao=[[NSMutableArrayalloc]initWithContentsOfFile:dpath];

    int i;

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

        NSDate *now=[NSDate date];

        NSDate *jq=[jqbiao objectAtIndex:i];

        NSDate *latedate=[jq laterDate:now];

        if (latedate==jq) {

            break;

        }

    }

    NSString *ipath=[[NSBundle mainBundle]pathForResource:@"jqbg"ofType:@"plist"];

    NSMutableArray *jqbg=[[NSMutableArrayalloc]initWithContentsOfFile:ipath];

    NSString *bgurl=[jqbg objectAtIndex:i];

    return bgurl;

    [jqbg release];

    [jqbiao release];

}

-(void)btnclick{

    self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[self whatjieqiis]]];

    AppDelegate *nowdelegate=[UIApplicationsharedApplication].delegate;

    nowdelegate.window.backgroundColor=[UIColorcolorWithPatternImage:[UIImage imageNamed:[self whatjieqiis]]];

}


原创粉丝点击