zoukankan      html  css  js  c++  java
  • UIButton上图片和文字的位置调整

    UIButton上图片和文字的位置调整

          UIButton 上默认是图片在左文字在右,而大多数情况这样默认的的显示形式都不能满足我们的需求,接下来我就这个问题分享一下我的心得。

          默认情况下,不设置的效果,都是居中实现

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

        button.frame = CGRectMake(50, 50, 150, 100);

        button.backgroundColor = [UIColor yellowColor];

        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        [button setTitle:@"title" forState:UIControlStateNormal];

        [button setImage:[UIImage imageNamed:@"tab5"] forState:UIControlStateNormal];

        [self.view addSubview:button];

    *********************************************************

    UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right);

    上面的四个数值是基于原位置而改变的例如:

        [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 60)];

        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 60, 0, 0)];

    title 的CGFloat right改变的60 是基于原位置的titleLabel的右边框向左平移60也就是到右边框的距离。

    image也是一样,距离原来imageView的左边框向右平移了60。

    *********************************************************

        [button setTitleEdgeInsets:UIEdgeInsetsMake(30, 0, 0, 30)];

        [button setImageEdgeInsets:UIEdgeInsetsMake(0, 30, 30, 0)];

    上下移动的原理同左右;

  • 相关阅读:
    KVM切换声音关闭
    tmux 快捷键
    arp绑定网关MAC地址错误
    javascript的字符串模板
    cheerio, dom操作模块
    footable动态载入数据
    node-js访问rest api的方法
    重装eclipse要做的事
    爬虫(三):对requests、xpath模块
    Java-基础篇(类和对象)
  • 原文地址:https://www.cnblogs.com/chamton/p/5052374.html
Copyright © 2011-2022 走看看