首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AsyncDisplayKit ASButtonNode setTitle不工作

AsyncDisplayKit ASButtonNode setTitle不工作
EN

Stack Overflow用户
提问于 2016-01-14 13:54:48
回答 3查看 1.1K关注 0票数 1

我使用AsyncDisplayKit的write按钮,使用ASButtonNode,但是当我使用- (void)setAttributedTitle:(NSAttributedString *)title forState:(ASButtonState)state的时候,我不能设置标题。它可以响应动作,但没有标题。是我担心还是需要设置其他东西?

下面是代码:

代码语言:javascript
复制
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];

谢谢。

EN

回答 3

Stack Overflow用户

发布于 2016-04-19 01:35:28

@leo,看起来你可能只需要测量一下你的ASButtonNode,然后再把它添加到视图中。

[button measure:...];

票数 1
EN

Stack Overflow用户

发布于 2016-04-14 15:51:10

请在此处引用此主题Add custom Button with AsyncDisplayKit

基本上,ASTextNode将被用作按钮,也可以在下面的函数示例中设置标题,颜色,字体粗细和颜色(在Swift中)

代码语言:javascript
复制
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
}
票数 0
EN

Stack Overflow用户

发布于 2017-10-13 16:07:52

您可以使用以下代码

代码语言:javascript
复制
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())
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34782573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档