PersonCell中带有约束的按钮隐藏了Swift按钮的一半

时间:2015-08-05 18:17:08

标签: ios swift button constraints

在personCell中创建一个按钮,该按钮显示Follow / Unfollow。 我在按钮中添加了以下约束:

Align Center Y to: Superview
Height = 43
Trailing space to: Superview

无论有没有约束,它仍然会切断按钮的一侧。 如果按钮应显示“跟随”,则只显示“ow”

PersonCell代码

class PersonCell: UITableViewCell {

@IBOutlet weak var followButton: UIButton!

var isFollowing: Bool?

var user: PFUser?
{
    didSet
    {
        self.configure()
    }
}

override func awakeFromNib()
{
    super.awakeFromNib()

    self.isFollowing = false
    self.followButton?.hidden = true
}

override func prepareForReuse()
{
    super.prepareForReuse()

    self.isFollowing = false
    self.followButton?.hidden = true
    self.textLabel?.text = ""
    self.user = nil
}

func configure()
{
    if let constUser = user
    {
        self.textLabel?.text = constUser.username

        // are we following this person?

        NetworkManager.sharedInstance.isFollowing(constUser, completionHandler: {
            (isFollowing, error) -> () in

            if let _ = error
            {
                // Alert the user, or otherwise modify the UI
            }
            else
            {
                self.isFollowing = isFollowing

                if isFollowing == true
                {
                    let image = UIImage(named: "UnfollowButton")
                    self.followButton?.setImage(image, forState: .Normal)
                }
                else
                {
                    let image = UIImage(named: "FollowButton")
                    self.followButton?.setImage(image, forState: .Normal)
                }

                self.followButton?.hidden = false
            }

        })
    }
}

@IBAction func didTapFollow(sender: UIButton)
{
    self.followButton?.enabled = false

    let newValue = !(self.isFollowing == true)
    NetworkManager.sharedInstance.updateFollowValue(newValue, user: self.user!) { (error) -> () in

        self.followButton?.enabled = true

        let image = (newValue == true) ? UIImage(named: "UnfollowButton") : UIImage(named: "FollowButton")
        self.followButton?.setImage(image, forState: .Normal)

        self.isFollowing = newValue
    }
}

}

我还不允许发布图片,但如果你需要查看它的外观,请看这个:

http://postimg.org/image/jnf47mnr1/

提前谢谢!

0 个答案:

没有答案