UISlider添加标签

时间:2016-05-31 10:24:39

标签: ios xcode label uislider

我可以在滑块上添加标签,但只有在移动滑块时才会出现标签我需要lebel总是在正确的位置和滑块的值

 - (IBAction)SinP:(id)sender {


    float increment = 1.0;
    if ([SinP isEqual:self.SinP]){
    float newValue1 = SinP.value /increment;
    SinP.value = floor(newValue1) * increment;
    }

   UIImageView *handleView1 = [SinP.subviews lastObject];
    UILabel *label = (UILabel*)[handleView1 viewWithTag:1010];
   if (label==nil) {
      label = [[UILabel alloc] initWithFrame:handleView1.bounds];
    label.tag = 1010;
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
     label.textAlignment = NSTextAlignmentCenter;
    [handleView1 addSubview:label];

   }
   label.text = [NSString stringWithFormat:@"%0.0f", self.SinP.value];
   _L01.text = [NSString stringWithFormat:@"%0.0f", self.SinP.value];
   self.T01.text = [@((int)SinP.value) stringValue];


}

1 个答案:

答案 0 :(得分:0)

做一件事,当应用程序在安装后第一次运行时,您将该日期保存在NSUserdefaults中。通过使用该日期,您可以获取当前日期和保存日期(第一个时间日期)之间的天数,然后返回截面tableview数据源方法中的行数天数。  //像appdlegate一样编写代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if(![[NSUserDefaults standardUserDefaults] objectForKey:@"installation_date"]) {
    [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"installation_date"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
return YES;
}

-(int)getNumberOfDays{
     NSString *start = @"2010-09-01";
     NSString *end = @"2010-12-01";

    NSDateFormatter *f = [[NSDateFormatter alloc] init];
   [f setDateFormat:@"yyyy-MM-dd"];
   NSDate *startDate = [f dateFromString:start];
   NSDate *endDate = [f dateFromString:end];

   NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
   NSDateComponents *components = [gregorianCalendar components:NSCalendarUnitDay
                                                fromDate:startDate
                                                  toDate:endDate
                                                  options:NSCalendarWrapComponents];
 return [components day];
}