触摸事件后更改UILabel文本颜色

时间:2018-04-03 16:19:31

标签: ios objective-c xcode uilabel textcolor

我有一些UILabel的滚动视图,我希望在标签上的标签后更改UILabel文字颜色。

我在循环中创建了UILabel,我试图弄清楚如何引用回到确切的UILabel以及如何在触摸后更改文本颜色。

-(void)barbuttondisplay{
UIScrollView * leftNaviNaviButtonView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,delegate.windowWidth, 44)];
[leftNaviNaviButtonView setContentSize:CGSizeMake([[newsgetcategoryDict objectForKey:@"category"]count]*101, 0)];
leftNaviNaviButtonView.userInteractionEnabled = YES;

[leftNaviNaviButtonView setScrollEnabled:YES];
[leftNaviNaviButtonView setShowsVerticalScrollIndicator:NO];
leftNaviNaviButtonView.showsHorizontalScrollIndicator=NO;

for(int i=0;i<[[newsgetcategoryDict objectForKey:@"category"]count];i++)
{
    UILabel * contentLable = [[[UILabel alloc]init]autorelease];
    [contentLable setFrame:CGRectMake((i*100)+10,5,80,30)];

    [contentLable setFont:[UIFont fontWithName:appFontRegular size:16]];
    [contentLable setText:[[[newsgetcategoryDict objectForKey:@"category"]objectAtIndex:i]objectForKey:@"category_name"]];
    if(catid == [[[newsgetcategoryDict objectForKey:@"category"]objectAtIndex:i]objectForKey:@"category_id"])
    {
        [contentLable setTextColor:AppThemeColor];
    }else{
        [contentLable setTextColor:headercolor];
    }
    //[contentLable setTextColor:headercolor];
    [contentLable setUserInteractionEnabled:YES];
    [contentLable setTextAlignment:NSTextAlignmentCenter];
    [contentLable setTag:i];
    [leftNaviNaviButtonView addSubview:contentLable];
    [contentLable setNumberOfLines:2];

    UITapGestureRecognizer *textTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotocategorypage:)];
    [contentLable addGestureRecognizer:textTap];

}


[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:negativeSpacer,[[[UIBarButtonItem alloc] initWithCustomView:leftNaviNaviButtonView]autorelease], nil]];
[leftNaviNaviButtonView release];
}

-(void)gotocategorypage:(UIGestureRecognizer*) sender
{

int tag =(int)(UIGestureRecognizer*)[sender.view tag];

if(![catid isEqualToString:[[[newsgetcategoryDict objectForKey:@"category"] objectAtIndex:tag] objectForKey:@"category_id"]])
{
    catid = [[[newsgetcategoryDict objectForKey:@"category"] objectAtIndex:tag] objectForKey:@"category_id"];


}else{
    catid = @"";

}

因此,在UILabel,&#34; catid&#34;设置,但我认为既然标签已经创建,所以它不会改变它的颜色?

0 个答案:

没有答案