如何在iPhone中将图像设置为UISegmentedControl? [英] How to set image to the UISegmentedControl in iPhone?

查看:107
本文介绍了如何在iPhone中将图像设置为UISegmentedControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手。我创建了UISegmentedControl有2个段。我想显示每个段而不是标题的图像。这是我的代码

I am new to iPhone development. I have created UISegmentedControl having 2 segments. I want to display images for each segment instead of title. Here is my code

NSArray *itemArray = [NSArray arrayWithObjects: @"segment1", @"segment2", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(5,100,300,40);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 1;
[self.view addSubview:segmentedControl];
[segmentedControl release]; 

但不应显示标题,segment1和segment2,而应将其替换为我拥有的图像。

But instead of displaying the title ,segment1 and segment2 it should be replaced with the images I have.

推荐答案

这几乎就是你所拥有的,只需传递一组UIImages而不是NSStrings。

It is almost exactly what you had, just pass an array of UIImages instead of NSStrings.

NSArray *itemArray = [NSArray arrayWithObjects:
    [UIImage imageNamed:@"segment1.png"],
    [UIImage imageNamed:@"segment2.png"],
    nil];

这篇关于如何在iPhone中将图像设置为UISegmentedControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆