Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UI分割控制背景图像用户更改_Iphone_Ios_Xcode - Fatal编程技术网

Iphone UI分割控制背景图像用户更改

Iphone UI分割控制背景图像用户更改,iphone,ios,xcode,Iphone,Ios,Xcode,我希望我的应用程序有一个设置,可以在用户按下UI分段控件中的某个分段时更改图像,但我只知道在导航栏中显示它。我将如何实现它,使设置有一个特定的视图,当用户按下一个段,然后按下“完成”时,它将恢复到一个带有该背景图像的新视图。您可以像这样更改分段控件的图像 UISegmentedControl*段 [segment setImage:UIImage forSegmentAtIndex:segmentIndex]; 或 编辑: 您可以尝试将值传递给newViewController - (IBA

我希望我的应用程序有一个设置,可以在用户按下UI分段控件中的某个分段时更改图像,但我只知道在导航栏中显示它。我将如何实现它,使设置有一个特定的视图,当用户按下一个段,然后按下“完成”时,它将恢复到一个带有该背景图像的新视图。

您可以像这样更改分段控件的图像 UISegmentedControl*段

[segment setImage:UIImage  forSegmentAtIndex:segmentIndex];

编辑:

您可以尝试将值传递给newViewController

- (IBAction)didChangeSegmentControl:(UISegmentedControl *)control {
   newViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
newViewController. selectedIndex =control.selectedSegmentIndex;
[self.navigationController pushViewController: newViewController animated:NO];    
}
@interface NewViewController : UIViewController
{
NSInteger selectedIndex;
}

@property(nonatomic)NSInteger selectedIndex;

@end
在此之前,必须在newViewController中设置属性

- (IBAction)didChangeSegmentControl:(UISegmentedControl *)control {
   newViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
newViewController. selectedIndex =control.selectedSegmentIndex;
[self.navigationController pushViewController: newViewController animated:NO];    
}
@interface NewViewController : UIViewController
{
NSInteger selectedIndex;
}

@property(nonatomic)NSInteger selectedIndex;

@end
以及在实施中

@implementation NewViewController

@synthesize selectedIndex;
//your codes
@end

您可以像这样更改分段控件的图像 UISegmentedControl*段

[segment setImage:UIImage  forSegmentAtIndex:segmentIndex];

编辑:

您可以尝试将值传递给newViewController

- (IBAction)didChangeSegmentControl:(UISegmentedControl *)control {
   newViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
newViewController. selectedIndex =control.selectedSegmentIndex;
[self.navigationController pushViewController: newViewController animated:NO];    
}
@interface NewViewController : UIViewController
{
NSInteger selectedIndex;
}

@property(nonatomic)NSInteger selectedIndex;

@end
在此之前,必须在newViewController中设置属性

- (IBAction)didChangeSegmentControl:(UISegmentedControl *)control {
   newViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
newViewController. selectedIndex =control.selectedSegmentIndex;
[self.navigationController pushViewController: newViewController animated:NO];    
}
@interface NewViewController : UIViewController
{
NSInteger selectedIndex;
}

@property(nonatomic)NSInteger selectedIndex;

@end
以及在实施中

@implementation NewViewController

@synthesize selectedIndex;
//your codes
@end

试试这几行代码

 NSArray *ary=[sgmntControl subviews];
 NSInteger intCount=0;
 for (id seg in ary) 
  for (id imageview in [seg subviews]) 
 if ([imageview isKindOfClass:[UIImageView class]])
  {
   if(intCount==1)
    {
    [imageview setimage:[UIImage imagenamed:@""]; 

    }
    else 
    {
   [imageview setimage:[UIImage imagenamed:@""]; 

    }


   }

试试这几行代码

 NSArray *ary=[sgmntControl subviews];
 NSInteger intCount=0;
 for (id seg in ary) 
  for (id imageview in [seg subviews]) 
 if ([imageview isKindOfClass:[UIImageView class]])
  {
   if(intCount==1)
    {
    [imageview setimage:[UIImage imagenamed:@""]; 

    }
    else 
    {
   [imageview setimage:[UIImage imagenamed:@""]; 

    }


   }


使用2个或更多按钮,而不是段:)我希望它是一个类似的设置。背景图像可以更改。请使用2个或多个按钮,而不是分段:)我希望它是一个类似于的设置。背景图像可以更改。你能解释一下吗,我在iOs中有点新。我将举一个例子说明[segment setImage:[UIImage ImageName:@“image1.png”]对于分段索引:0];[segment setImage:[UIImage ImageName:@“image2.png”]用于分段索引:1];segment是要设置图像的分段控件。是否可以将其传递到其他视图?例如,我在setingsviewcontroller.m中实现了这一点,我将如何在NewViewController中传递按下的段的值?我不理解您的需要。我只给出了为UISegmentedControls设置图像的代码,例如:我将片段声明为SettingViewController。单击过程中的线段或将其保存到另一个视图时,例如:NewViewController。像这样。你能解释一下吗,我在iOs中有点新。我将举一个例子说明[segment setImage:[UIImage ImageName:@“image1.png”]对于分段索引:0];[segment setImage:[UIImage ImageName:@“image2.png”]用于分段索引:1];segment是要设置图像的分段控件。是否可以将其传递到其他视图?例如,我在setingsviewcontroller.m中实现了这一点,我将如何在NewViewController中传递按下的段的值?我不理解您的需要。我只给出了为UISegmentedControls设置图像的代码,例如:我将片段声明为SettingViewController。单击过程中的线段或将其保存到另一个视图时,例如:NewViewController。就像这样。在这个例子中,我们只是将片段控制上的imageview作为子视图传递,但在我在wwdc中看到如何使用此方法之前,使用is kindclass方法,所以我尝试了,这对我来说是可行的。你能将其传递到另一个视图吗?例如,我在setingsviewcontroller.m中实现了这一点,我将如何在NewViewController中传递被按下的段的值?为此,只需在段上传递一个全局变量,然后在下一个视图控制器中使用该变量。@bry您是计算机语言的新手。好的,我将帮助您。哦,这是一个单例,对吗?我不知道怎么做。我已经阅读了其他关于NSUserDefaults的教程。在本教程中,我们只是将分段控制上的imageview作为子视图传递,但在wwdc中看到如何使用is kindclass方法之前,我使用了该方法,所以我尝试了,这对我来说是可行的。你能将其传递到另一个视图吗?例如,我在setingsviewcontroller.m中实现了这一点,我将如何在NewViewController中传递被按下的段的值?为此,只需在段上传递一个全局变量,然后在下一个视图控制器中使用该变量。@bry您是计算机语言的新手。好的,我将帮助您。哦,这是一个单例,对吗?我不知道怎么做。我已经阅读了其他关于NSUserdefaultshow的教程,我会将它传递到另一个视图吗?例如:我将段声明为SettingViewController。单击过程中的线段或将其保存到另一个视图时,例如:NewViewController。像那样。我将如何将其传递给另一个视图?例如:我将该段声明给SettingViewController。单击过程中的线段或将其保存到另一个视图时,例如:NewViewController。像那样。