根据用户选择调整按钮/图像的大小

时间:2019-06-20 16:02:28

标签: ios objective-c tweak

,我想为用户提供根据用户的选择来选择按钮大小的选项。我可以这样做吗?

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

0 个答案:

没有答案