我有一个字符串,其中最后一个单词与整个字符串中的其他单词相比总是具有不同的颜色,例如:如果字符串颜色为黑色,则语句中的最后一个单词将为红色.我正在使用NSAttributed字符串,如下所示:
NSDictionary *attrDict = [NSDictionary dictionaryWithObject:[UIFont fontWithName:Arial size:16.0] forKey:NSFontAttributeName];
NSMutableAttributedString *AattrString = [[NSMutableAttributedString alloc] initWithString:@"This is a" attributes: attrDict];
Run Code Online (Sandbox Code Playgroud)
我会为最后一个单词制作类似的NSAttributedString,并用第一个字符串修改它.
问题:我想在字符串中添加颜色和字体.我已经使用字典处理字体了.但是我可以在同一个字典中添加颜色处理程序/代码,或者在NSAttributedString上使用"addAttribute:"是添加颜色或任何其他属性的唯一方法吗?
嗨,我想addAttribute
在Swift3中使用.
我想要只设置粗体IDNAME.
这就是我想要的.
let boldUsername = NSMutableAttributedString(string: "IDNAME hi nice 2 meet you :D #HELLOW")
// boldUsername.addAttribute(NSFontAttributeName, value: UIFont(name: "SFUIText-Bold", size: 14)!, range: (boldUsername.string as NSString).range(of: " "))
boldUsername.addAttribute(NSFontAttributeName, value: UIFont(name: "SFUIText-Bold", size: 14)!, range: NSRange(location: 0, length: 5))
Run Code Online (Sandbox Code Playgroud)
我如何获得IDNAME的索引,即每次都不同?
- >有没有办法分割空间并获得索引?
我有一个像下面这样的 xml 文件,我需要添加一个带有一些子节点和属性的新节点。
<custscales>
<custscale sclNo="1" type="lin">
<scaleName>Custom Scale Lin</scaleName>
<jsfunc>custLin</jsfunc>
</custscale>
<custscale sclNo="2" type="map">
<scaleName>Custome Scale Map</scaleName>
<jsfunc>custMap</jsfunc>
</custscale>
<custscale sclNo="3" type="pol">
<scaleName>Custome Scale Pol</scaleName>
<jsfunc>custPol</jsfunc>
</custscale>
<custscale sclNo="4" type="tbl1">
<scaleName>Custome Scale Table</scaleName>
<jsfunc>custTbl1</jsfunc>
</custscale>
</custscales>
Run Code Online (Sandbox Code Playgroud)
现在我想要一个新的 custscale 节点,如下所示在我现有的 xml 文件中:
<custscale sclNo="5" type="tbl1">
<scaleName>Custome Scale New</scaleName>
<jsfunc>custTbl1</jsfunc>
</custscale>
Run Code Online (Sandbox Code Playgroud) 我在Magento多选属性上使用addAttributeToFilter时遇到了麻烦.
我有汽车制造的多重选择属性,所以内容是'奥迪','宝马'等等.在我的例子中,我有一个轮胎产品,我从多个选择中选择了5个.
我想展示制作'宝马'作为其选定领域之一的产品.
我尝试了以下所有不起作用:
$products->addAttributeToFilter('make', array('like' => '%BMW%'));
$products->addFieldToFilter('make', array('like' => '%BMW%'));
$products->addAttributeToFilter('make', array('like' => '%38%')); // id of the attribute option
Run Code Online (Sandbox Code Playgroud)
似乎没什么用.
在magento中,我有一个名为cl_designer的属性,它是一个选择下拉选项.我想在其上过滤产品系列,如下所示:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('cl_designer', array('like' => $filter));
Run Code Online (Sandbox Code Playgroud)
但它不起作用!当我使用$ collection-> getselect()打印出查询时,我发现它正在将$ filter与catalog_product_entity_int.value进行比较.但这是错误的,因为对于select选项,catalog_product_entity_int.value是option_id,而不是值.那么如何让它过滤实际的期权价值呢?
下面的代码将字符串@"10加到2的幂= 10 [2]"并将红色设置为数字2
问:我想有这种(幻想)效果:
(请注意,我正在寻找一种通用效果,它代表一个小的,稍微高于行数 - 就在一个字符串之后,不一定是"......的力量",但它应该看起来像上图):
-(void)textAttribute
{
NSString *myString = @"ten to the power of two = 10[2]";
NSRange start = [myString rangeOfString:@"["];
NSRange end = [myString rangeOfString:@"]"];
if (start.location != NSNotFound && end.location != NSNotFound && end.location > start.location) {
//NSString *betweenBraces = [myString substringWithRange:NSMakeRange(start.location+1, end.location-(start.location+1))];
NSRange myRange = NSMakeRange(start.location+1, end.location-(start.location+1));
NSMutableAttributedString *s =
[[NSMutableAttributedString alloc] initWithString:myString];
UIColor *powerColor = [UIColor redColor];
[s addAttribute:NSForegroundColorAttributeName value:powerColor range:myRange];
triggerLabel.text = [NSString stringWithFormat:@"Trigger words:%@",powerColor];
triggerLabel.attributedText = s;
}
}
Run Code Online (Sandbox Code Playgroud) 使用 HtmlTextWriter 将多个类添加到标签的最佳方法是什么?
我想做的是类似的事情......
writer.AddAttribute(HtmlTextWriterAttribute.Class, "Class1");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "Class2");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
Run Code Online (Sandbox Code Playgroud)
导致...
<table class="Class1 Class2">
Run Code Online (Sandbox Code Playgroud)
我很感激我能做到...
writer.AddAttribute(HtmlTextWriterAttribute.Class, "Class1 Class2");
Run Code Online (Sandbox Code Playgroud)
然而,在动态构建控件时并不总是如此简单。是否有其他方法可以将类“附加”到标签?
我想为Magento中的管理员用户添加一些新属性.这些用户与客户不同(只是为了说清楚),并且只能设置他们的用户/名称/姓氏/邮件/通行证,但我想添加一些新属性.
为此,我想我可以使用addattribute函数,但我需要找出这些管理员用户的ID.例如,如果我想向客户添加新属性,我可以使用如下函数:
$setup->addAttribute('customer','attribute_id', $attr );
Run Code Online (Sandbox Code Playgroud)
因此,在这种情况下,"客户"是客户的身份.如何找出管理员用户使用的ID?(这个问题可以扩展到"如何在Magento中找到不同类型属性的不同id?").
==有可能无法改变这一点.我看了一下admin_user表,它非常简单,所有字段都在那里.所以在这种情况下也许没有属性.==
谢谢
我有一个转发器,我想在属性上添加一个鼠标到它的项目.
是否可以在运行时添加属性,如果是,那么如何?