如何以编程方式将UIView(带子视图为UIImageViews)转换为UIImage?
这是一种常见做法吗?
嗨,在我的应用程序中我有一个数组.因为我有很多UIView和UIImageView组件,我想从该数组中获取每个组件,并且必须知道是图像视图还是视图,如果是imageview,我必须更改该图像的图像.但我没有任何想法如何知道组件是imageview或视图.如果有人知道,请告诉我识别组件类型的方法.请帮我解决这个问题.
for (int i=0; i<[array count]; i++){
// here i have to know wether the component is imageview or view and based on that i have to do below operations
UIView *view1=[array objectAtIndex:i];
NSLog(@"%@",[array objectAtIndex:i]);
if (130==view1.tag){
view1.backgroundColor=[UIColor redColor];
}
UIImageView *image1=[array objectAtIndex:i];
if (132==image1.tag){
image1.image=[UIImage imageNamed:@"Approve2.png"];
}
}
Run Code Online (Sandbox Code Playgroud) 我正在添加一些名为*cellSeparator和其他UILabels的动态UIView ...现在发生的事情是当我再次调用此代码然后重写标签文本并覆盖以前创建的标签文本...我对此不是很了解ios development.so任何人都可以告诉我如何在再次创建之前动态删除这个UIView?因为UIView是动态创建的我不知道如何删除该UIview
UILabel *indexLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-150, self.view.frame.size.width/2,30)];
[indexLabel setBackgroundColor:[UIColor clearColor]];
indexLabel.textColor = [UIColor whiteColor];
indexLabel.text = @"Details:-";
indexLabel.font = [UIFont systemFontOfSize:20.00];
UILabel *tagLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-120, self.view.frame.size.width/2, 30)];
tagLabel.backgroundColor = [UIColor clearColor];
NSLog(@"LOg %@",imageId);
NSLog(@"LOg %@",imageStyle);
NSLog(@"LOg %@",imageType);
NSLog(@"LOg %@",imageWeight);
tagLabel.text = [NSString stringWithFormat:@"The Id of Jewl Is: %@",imageId];
imageTypelabel= [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-90, self.view.frame.size.width/2, 30)];
imageTypelabel.backgroundColor = [UIColor clearColor];
imageTypelabel.text = [NSString stringWithFormat:@"The Type of Jewl Is: %@",imageType];
imageStylelabel = [[UILabel alloc] initWithFrame:CGRectMake(20, …Run Code Online (Sandbox Code Playgroud) 当我在我正在使用它的UITableViewCell子类中时,当我尝试访问我的cellFront对象的title属性时,我收到以下错误:

然而我导入了CellFront.h,它具有以下属性:

我究竟做错了什么?我在Xcode 4.6和iOS上,所以我不需要合成我的变量.
我对ios很新.我正在开发一个项目,它经常在整个应用程序中使用某个UIView类.这个类只是一个用背景颜色做一些透明度的图像.这到目前为止工作正常.这个类有时作为单独的UIView存在,有时作为按钮子视图存在.
当我将这个UIVut添加到UIButton作为子视图时,UIView的全部内容以完整大小显示,但按钮的可点击区域保持xib中定义的大小,除非关闭Use Autolayout(即使我手动尝试)设置按钮的框架.)
我想在xib上放置一个UIButton作为占位符,然后根据初始化的UIView的叠加图像的大小定义其大小/可点击区域.
这应该是可能的,还是我误解了xib文件/ autolayout的用法?
在ViewDidLoad下我有......
- (void)viewDidLoad{
[theButton addSubview:_theView];
CGRect buttonFrame = theButton.frame;
buttonFrame.size = CGSizeMake(_theView.getSize.width,_theView.getSize.height);
[theButton setFrame:buttonFrame];
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试调用setFrame之前和之后打印按钮信息时,框架保持相同的大小.
(注意'_theView.getSize'是我添加的)
我有两个UIViews,我需要画一个矩形(或)得到最小矩形的框架UIViews.我怎么能得到这个?
我试图通过隐藏UINavigationBar和UIStatusBar来全屏显示View(UIBubbleTable实例位于View控制器视图的顶部).但由于某种原因,黑色空间仍位于顶部:
NSLog(@"view frame before:%@", NSStringFromCGRect(self.view.frame));
NSLog(@"view bounds before:%@", NSStringFromCGRect(self.view.bounds));
NSLog(@"bubble table frame before:%@", NSStringFromCGRect(self.bubbleTable.frame));
NSLog(@"bubble table bounds before:%@", NSStringFromCGRect(self.bubbleTable.bounds));
[self.view hideKeyboard];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBar.hidden = YES;
self.containerView.hidden = YES;
[self.view setFrame:[[UIScreen mainScreen] bounds]];
[self.bubbleTable setFrame:self.view.bounds];
NSLog(@"view frame after:%@", NSStringFromCGRect(self.view.frame));
NSLog(@"view bounds after:%@", NSStringFromCGRect(self.view.bounds));
NSLog(@"bubble table frame after:%@", NSStringFromCGRect(self.bubbleTable.frame));
NSLog(@"bubble table bounds after:%@", NSStringFromCGRect(self.bubbleTable.bounds));
Run Code Online (Sandbox Code Playgroud)
NSLog的:
2013-07-06 22:05:18.068 KIM[5085:c07] view frame before:{{0, 0}, {320, 504}}
2013-07-06 22:05:18.068 KIM[5085:c07] view bounds before:{{0, 0}, {320, 504}}
2013-07-06 22:05:18.069 KIM[5085:c07] bubble table frame before:{{0, …Run Code Online (Sandbox Code Playgroud) 我已经使用了一些断点,发现单元格的init方法实际上已被调用,所以我知道我的tableview正在使用自定义的tableView单元类.这是类实现:
#import "FCTableViewCell.h"
@implementation FCTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.textLabel.frame = CGRectMake(10.0, 19.0, 240.0, 27.0);
// Initialization code
}
return self;
}
-(void)layoutSubViews
{
[super layoutSubviews];
self.textLabel.frame = CGRectMake(10.0, 19.0, 240.0, 27.0);
self.textLabel.adjustsFontSizeToFitWidth = YES;
self.textLabel.minimumScaleFactor = 0.8;
self.textLabel.textAlignment = NSTextAlignmentCenter;
self.textLabel.font = [UIFont fontWithName:@"Avenir" size:21.0];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
Run Code Online (Sandbox Code Playgroud) 上下文
UIViewController一个UINavigationController堆栈内的UIViewController我UILabel在(x,y)坐标(0,0)处以编程方式添加UILabel到self.view(这是在UIViewController中)或添加UILabel到a UIView,这UIView是self.containerViewself.containerView 通过以下代码创建并添加到视图中:
- (void)addContainerView
{
// Create a UIView with same frame as the screen bounds
CGRect containerViewFrame = [[UIScreen mainScreen] applicationFrame];
self.containerView = [[UIView alloc] initWithFrame:containerViewFrame];
// Give the UIView a red background
self.containerView.backgroundColor = [UIColor redColor];
// Add the view
[self.view addSubview:self.containerView];
}
Run Code Online (Sandbox Code Playgroud)
将UILabel通过该代码添加:
- (void)addTestLabel
{
self.navigationController.navigationBarHidden = YES;
CGRect frame = CGRectMake(0, 0, 100, …Run Code Online (Sandbox Code Playgroud) 我试图在主视图后面放置一个带有模糊效果的半透明图像,类似于Apple在iOS 7中的操作方式.实现这种效果的最佳,最有效的方法是什么?
uiview ×10
ios ×9
iphone ×4
objective-c ×3
uitableview ×3
autolayout ×1
fullscreen ×1
ipad ×1
uibutton ×1
uiimageview ×1
uilabel ×1
xcode ×1
xib ×1