首页 > 解决方案 > 根据用户的选择调整按钮/图像的大小

问题描述

,我想让用户根据用户的选择选择按钮大小......请问我可以这样做吗?

mytweak.xm

        UIButton *respringButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
    respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height / 2 - 80, 60, 60);
    [respringButton setImage:[UIImage imageWithContentsOfFile: respring] forState:UIControlStateNormal];
    [respringButton setTitle:@"respring" forState:UIControlStateNormal];
    [respringButton addTarget:self action:@selector(reboot) forControlEvents:UIControlEventTouchUpInside];

    if(style != 1) {
    respringButton.tintColor = tintColor;
    } else {
    if(defaultTheme1 == 0) {
respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height  , 60, 60);
    } else if (defaultTheme1 == 1) {
respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height , 80, 80);
    } else if (defaultTheme1 == 2) {
respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height , 100, 100);
    }
    }
    [respringButton centerVertically];
    [myView addSubview:respringButton];

mytweak.h

        - (void)centerVertically {
            // Spacing between the text and the image
            CGFloat spacing = 5.0;

            // Lower the text and push it left so it appears centered below the image
            CGSize imageSize = self.imageView.frame.size;
            self.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, - (imageSize.height + spacing),- 120.0);

            // Raise the image and push it right so it appears centered above the text
            CGSize titleSize = self.titleLabel.frame.size;
            self.imageEdgeInsets = UIEdgeInsetsMake(- (titleSize.height + spacing), 0.0, 0.0, - titleSize.width);
        }
     @end

标签: iosobjective-ctweak

解决方案


推荐阅读