label的attributes相关

  NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    NSDictionary*attribute = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle};
    CGSize size = [text boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;

    [text drawWithRect:CGRectMake(10, 10,300, size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil];




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Label长文本手机上不显示处理 // Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { nodeModule: cc.Node, nodeContainer: cc.Node, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { }, // update (dt) {}, setLongText(longText){ // 界限值 const WORDS_COUNT = 100; let str = longText; let left = ''; do{ let index = str.indexOf('\n'); if(index == -1){ break; } left = left + str.substring(0, index); str = str.substring(index); while(str.length > 0 && str[0] == '\n'){ left = left + str[0]; str = str.substring(1); } if(left.length > WORDS_COUNT){ if(left.length >= 1&& left[left.length - 1] == '\n'){ left = left.substring(0, left.length -1); } this.addModule(left); left = ''; } }while(str.length > WORDS_COUNT); if(left != ''){ this.addModule(left); } if(str != ''){ this.addModule(str); } }, addModule(text){ cc.log('##text##', text); let node = cc.instantiate(this.nodeModule); node.active = true; node.getComponent(cc.Label).string = text; this.nodeContainer.addChild(node); }, onClick(){ this.setLongText(`

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值