我使用AsyncDisplayKit的write按钮,使用ASButtonNode,但是当我使用- (void)setAttributedTitle:(NSAttributedString *)title forState:(ASButtonState)state的时候,我不能设置标题。它可以响应动作,但没有标题。是我担心还是需要设置其他东西?
下面是代码:
NSDictionary *placeholderAttrs = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-LightItalic" size:14.0f] , NSForegroundColorAttributeName: [UIColor greenColor] };
ASButtonNode *button = [[ASButtonNode alloc] init];
[button setAttributedTitle:[[NSAttributedString alloc] initWithString:@"button" attributes:placeholderAttrs] forState:ASButtonStateNormal];
[button addTarget:self action:@selector(action:) forControlEvents:ASControlNodeEventTouchUpInside];
[button setFrame:CGRectMake(20, 20, 100, 44)];
button.backgroundColor = [UIColor redColor];
button.titleNode.displaysAsynchronously = NO;
[self.view addSubnode:button];谢谢。
发布于 2016-04-19 01:35:28
@leo,看起来你可能只需要测量一下你的ASButtonNode,然后再把它添加到视图中。
[button measure:...];
发布于 2016-04-14 15:51:10
请在此处引用此主题Add custom Button with AsyncDisplayKit
基本上,ASTextNode将被用作按钮,也可以在下面的函数示例中设置标题,颜色,字体粗细和颜色(在Swift中)
func configureTextNode(text: String, size: CGFloat, frame : CGRect = CGRectMake(0,0,0,0), bold: Bool = false, color: UIColor = UIColor.whiteColor(), textAlignment: NSTextAlignment = .Left) -> ASTextNode {
let textNode = ASTextNode()
let range = NSMakeRange(0, text.characters.count)
// Set String
let mutableString = NSMutableAttributedString(string: text) // Set string
// Set size and font-weight
let fontSize = bold ? UIFont.boldSystemFontOfSize(size) : UIFont.systemFontOfSize(size)
mutableString.addAttribute(NSFontAttributeName, value: fontSize, range: range)
// Set text color
mutableString.addAttribute(NSForegroundColorAttributeName, value: color, range: range)
// Set alignment
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = textAlignment
mutableString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: range)
// Add attributes into node
textNode.attributedString = mutableString
// Node Frame
textNode.frame = frame
return textNode
}发布于 2017-10-13 16:07:52
您可以使用以下代码
fileprivate var noteButtonNode : ASButtonNode = ASButtonNode()
addSubnode(noteButtonNode)
let attributedTitle : NSAttributedString = NSAttributedString(
string: "Your_Text",
attributes: [
NSFontAttributeName: UIFont.init(name: Fonts.Your_Font, size: 16)!,
NSForegroundColorAttributeName: Colors.Your_Color
])
noteButtonNode.setAttributedTitle(attributedTitle, for: ASControlState())https://stackoverflow.com/questions/34782573
复制相似问题