滚动视图有许多标签

时间:2016-07-14 15:41:08

标签: ios swift

我创建了一个滚动视图。

我正在使用Storyboard,但是当我将这几个标签添加到我的ViewController并为它们设置正确的约束时,它在iPhone 5s上看起来很好,但在iPhone 6s上看起来很奇怪,因为下面会有太多的空间最后一个标签。

因此,当我在ViewController中设置视图的高度时,我应该如何摆脱较大设备上的空间?

我的约束可能存在问题。

我在iPhone 5s上的观点:

enter image description here

我在iPhone 6s上的观点:

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用此功能计算文本渲染大小:

$ ssh bastion -Tv

OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g-fips  1 Mar 2016
debug1: Reading configuration data /home/user/.ssh/config
debug1: /home/user/.ssh/config line 1: Applying options for bastion
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 10.22.105.143 [10.22.105.143] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/myapp3-staging.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/myapp3-staging.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to 10.22.105.143:22 as 'ec2-user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:xMwdmyTxChXwolpH/oDKjs7PObriTFvycACdz9U2QPA
debug1: Host '10.22.105.143' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:6
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: myuser@example.com
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: myuser@example.com
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/user/.ssh/myapp3-staging.pem
debug1: Authentication succeeded (publickey).
Authenticated to 10.22.105.143 ([10.22.105.143]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: Requesting authentication agent forwarding.
debug1: Sending environment.
debug1: Sending env LANG = en_IN

夫特:

//ARC code
//font: render font
//renderMaxWidth: max width of a line
//lineBreakMode: line break mode
- (CGSize) calculateLabelRenderSizeWith:(UIFont *) font renderMaxWidth:(CGFloat) width lineBreakMode:(NSLineBreakMode) mode 
{
    CGSize availableSize = CGSizeZero;
    availableSize.width = width;
    availableSize.height = MAXFLOAT;
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.lineBreakMode = mode;

    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    NSDictionary *attributes = @{
                             NSFontAttributeName: font,
                             NSParagraphStyleAttributeName: style
                             };
    CGSize textNodeSize = [self boundingRectWithSize:availableSize
                                         options:options
                                      attributes:attributes
                                         context:nil].size;
    return textNodeSize;
}