iphone - 如何调整 UISwitch 按钮的大小?

标签 iphone ios xcode uitableview uiswitch

我想调整附加在 UITableView 上的 UISwitch 按钮的大小。我在谷歌上找到了一些帮助,并使用 CGAffineTransformMakeScale 成功完成了这项工作,但是当我改变这个开关按钮的位置时,我遇到了一个问题,它变成了它自己的原始大小,可能是因为它在表格 View 上,但我在 ViewDidLoad 委托(delegate)中调整它的大小。这就是我正在做的事情。

- (void)viewDidLoad{
 switchFB = [[UISwitch alloc] initWithFrame:CGRectMake(227, 8, 79, 27)];
switchFB.transform= CGAffineTransformMakeScale(0.7, 0.7);}

并在单元格中为索引路径处的行

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{`static NSString *CellIdentifier = @"SettingsCell";`

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

请检查我哪里做错了,如果我的程序不正确,那么您能否建议我一些更好的方法来做到这一点。这对我来说很棒。提前致谢。

最佳答案

试试这个

 UISwitch *mySwitch = [UISwitch new];
mySwitch.transform = CGAffineTransformMakeScale(0.75, 0.75);

关于iphone - 如何调整 UISwitch 按钮的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15196564/

相关文章:

ios - UITableView.automaticDimension 高度即将到来 -1

ios - ScrollBar 在手动滚动时添加垂直偏移

cocoa - 引用自的框架错误 : ".objc_class_name_XXX",

ios - 在 Xcode 6 中,使用 UIPinchGestureRecognizer 中的值缩放图像差异中的值

ios - 在 SwiftUI 中获取文本的宽度

ios - 如何在 Swift 中将新单元格插入 UITableView

ios - Xcode Charles(HTTP 代理)不捕获本地主机流量

iphone - 推送后如何更改所选单元格的背景颜色?

iphone - 设置游戏中心以允许通过蜂窝网络进行连接

ios - 添加分享按钮 - Swift