我制作了一个自定义 UIPickerView,但我希望 UILabel 在像这样滚动到选定行时更改颜色;
有什么想法吗?
编辑: 我想做的是在进行选择的同时更改 UILabel 的颜色,即在轮子转动时,而不是之后。
到目前为止,这是我所做的,它会在您做出选择后更改 UILabel 的颜色:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
AILabel * pickerRow = view ? (AILabel *)view:[[[AILabel alloc] initWithFrame:CGRectMake(0, 0, 140, 40)] autorelease];
pickerRow.backgroundColor = [UIColor clearColor];
pickerRow.font = [UIFont boldSystemFontOfSize:18.0f];
pickerRow.insets = UIEdgeInsetsMake(0, 10, 0, 0);
if(component == 0)
{
pickerRow.text = [self.numberArray objectAtIndex:row];
if ( row == number )
{
pickerRow.alpha = 0.0f;
[UIView animateWithDuration: 0.33f
delay: 0.0f
options: UIViewAnimationOptionCurveEaseOut
animations:^{
pickerRow.textColor = [UIColor whiteColor];
pickerRow.shadowColor = [UIColor blackColor];
pickerRow.shadowOffset = CGSizeMake(0.0f, 1.0f);
pickerRow.alpha = 1.0f;
}
completion:^(BOOL finished){
}];
}
else
{
pickerRow.textColor = [UIColor blackColor];
pickerRow.shadowColor = [UIColor whiteColor];
pickerRow.shadowOffset = CGSizeMake(0.0f, 1.0f);
}
}
else
{
pickerRow.text = [self.durationArray objectAtIndex:row];
if ( row == duration )
{
pickerRow.alpha = 0.0f;
[UIView animateWithDuration: 0.33f
delay: 0.0f
options: UIViewAnimationOptionCurveEaseOut
animations:^{
pickerRow.textColor = [UIColor whiteColor];
pickerRow.shadowColor = [UIColor blackColor];
pickerRow.shadowOffset = CGSizeMake(0.0f, 1.0f);
pickerRow.alpha = 1.0f;
}
completion:^(BOOL finished){
}];
}
else
{
pickerRow.textColor = [UIColor blackColor];
pickerRow.shadowColor = [UIColor whiteColor];
pickerRow.shadowOffset = CGSizeMake(0.0f, 1.0f);
}
}
return pickerRow;
}
AILabel 只是一个自定义的 UILabel,没有什么特别之处。 'number' 变量是第一个组件中的当前选定值。 'duration' 变量是第二个组件中的当前选定值。
希望这更清楚
干杯
最佳答案
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = (UILabel*) view;
if (label == nil) {
label = [[UILabel alloc] init];
}
label.textColor = [UIColor RedColor];
CGSize rowSize = [pickerView rowSizeForComponent:component];
CGRect labelRect = CGRectMake (0, 0, rowSize.width, rowSize.height);
[label setFrame:labelRect];
return label;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
UILabel *selectedRow = (UILabel *)[pickerView viewForRow:row forComponent:component];
selectedRow.textColor = [UIColor blueColor];
}
关于iphone - UIPickerView 选中行标签颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16477598/
我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
如何使用Ruby的默认Curses库获取颜色?所以像这样:puts"\e[0m\e[30;47mtest\e[0m"效果很好。在浅灰色背景上呈现漂亮的黑色。但是这个:#!/usr/bin/envrubyrequire'curses'Curses.noecho#donotshowtypedkeysCurses.init_screenCurses.stdscr.keypad(true)#enablearrowkeys(forpageup/down)Curses.stdscr.nodelay=1Curses.clearCurses.setpos(0,0)Curses.addstr"Hello
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基
我有一个div,它根据表单是否正确提交而改变。我想知道是否可以检查类的特定元素?开始元素看起来像这样。如果输入不正确,添加错误类。 最佳答案 试试这个:browser.div(:id=>"myerrortest").class_name更多信息:http://watir.github.com/watir-webdriver/doc/Watir/HTMLElement.html#class_name-instance_method另一种选择是只查看具有您期望的类的div是否存在browser.div((:id=>"myerrortes
我有这样的HTML代码:Label1Value1Label2Value2...我的代码不起作用。doc.css("first").eachdo|item|label=item.css("dt")value=item.css("dd")end显示所有首先标记,然后标记标签,我需要“标签:值” 最佳答案 首先,您的HTML应该有和中的元素:Label1Value1Label2Value2...但这不会改变您解析它的方式。你想找到s并遍历它们,然后在每个你可以使用next_element得到;像这样:doc=Nokogiri::HTML(
我有以下不起作用的代码:=form_for(resource,:as=>resource_name,:url=>session_path(resource_name),:html=>{:class=>"well"})do|f|=f.label:email=f.email_field:email=f.label:password=f.password_field:password-ifdevise_mapping.rememberable?%p=f.label:remember_me,:class=>"checkbox"=f.check_box:remember_me,:class=>"
我正在遍历数组中的一组标签名称,我想使用构建器打印每个标签名称,而不是求助于“我认为:builder=Nokogiri::XML::Builder.newdo|xml|fortagintagsxml.tag!tag,somevalendend会这样做,但它只是创建名称为“tag”的标签,并将标签变量作为元素的文本值。有人可以帮忙吗?这个看起来应该比较简单,我刚刚在搜索引擎上找不到答案。我可能没有以正确的方式提问。 最佳答案 尝试以下操作。如果我没记错的话,我添加了一个根节点,因为Nokogiri需要一个。builder=Nokogi
我想要像“嘿那里”这样的东西变成,例如,#316583。我希望将任意长度的字符串“归结”为十六进制颜色。我不知道从哪里开始。我在想,每个字符串的MD5散列都是不同的-但如何将该散列转换为十六进制颜色数字? 最佳答案 你可以只取几位前几位:require'digest/md5'color=Digest::MD5.hexdigest('Mytext')[0..5] 关于ruby-如何使用Ruby基于字母数字字符串生成颜色?,我们在StackOverflow上找到一个类似的问题:
我有一个偏爱:如何将像o.office这样的值插入到属性中?value="#{o.office}"无效。 最佳答案 'type='text'/>或者你可以使用表单助手 关于ruby-on-rails-如何将变量值插入ERB模板中的HTML标签?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6172174/