iOS-UIView-设置背景图片4种方式】的更多相关文章

一 . 设置UIView的背景图片 1.将图片作为UIView的背景色,该方法过于占内存,不建议使用.     //1.imageNamed方式 self.view.backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"image.jpg"]];       //2.方式        NSString *path = [[NSBundlemainBundle]pathForResource:@&quo…
http://blog.csdn.net/qijianli/article/details/7777268 项目中,可能需要我们为某个视图设置背景图片,而API中UIView没有设置背景图片的方法,那么该如何实现呢? 第一种方法: 利用的UIView的设置背景颜色方法,用图片做图案颜色,然后传给背景颜色. UIColor *bgColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"bgImg.png"]; UIVie…
方法1. setStylSheet{"QDialog{background-image:url()"}}  //使用styleSheet 这种方法的好处是继承它的dialog都会自动设置背景,例如更换皮肤就是一个不错的选择 方法2. QPalette pal; pal.setBrush(QPalette::Background,QBrush(QPixmap("")));            this->setPalette(pal); 方法3.在paintE…
方法1. setStylSheet{"QDialog{background-image:url()"}}  //使用styleSheet 这种方法的好处是继承它的dialog都会自动设置背景,例如更换皮肤就是一个不错的选择 方法2. QPalette pal; pal.setBrush(QPalette::Background,QBrush(QPixmap("")));            this->setPalette(pal); 方法3.在paintE…
之前做过类似的功能,现在记录一下,来来来... 效果图: 说明=========================== 方法1: 说明:无返回值 用法:直接调用方法.原理是在view的layer层添加. 方法2: 说明:先返回一个Image,再使用 用法:若是image背景,直接使用,若是color背景,用 [UIColor colorWithPatternImage:image]即可. 代码=========================== 方法1: -(void)createByCAGra…
1.uiscrollview 设置背景图片 // Setup the Scroll ViewUIScrollView*tempScrollView=(UIScrollView*)self.view;tempScrollView.contentSize=CGSizeMake(320,720); // Set Stationary Background, so that while the user scroll the background is// fixed.UIImage*img =[UII…
给UIView添加背景图片 //默认情况下只能设置UIView的背景颜色,不能给UIView设置背景图片,但通过绘图知识可以做到 - (void)drawRect:(CGRect)rect { [super drawRect:rect]; [[UIImage imageNamed:@"mainCellBackground"]drawInRect:rect]; } 如果在某个时间点,view的frame变化了,需要调用 [view setNeedsDisplay]; 方法在下次屏幕刷新时…
创建UIImage的方法有两种: UIImage *image = [UIImageimageNamed:@"image.jpg"];//这种不释放内存,要缓存 NSString *path = [[NSBundlemainBundle]pathForResource:@"image"ofType:@"jpg"]; UIImage *image1 = [UIImageimageWithContentsOfFile:path];//这种会释放内存…
怎样给UIview添加背景图片呢很简单,就是先给view添加一个subview,然后设为背景图片: 效果图如下: 很简单直接上代码: //设置内容 self.myTopView.backgroundColor=[UIColor grayColor]; self.nameLabel.textColor=[UIColor blackColor]; self.addLabel.textColor=[UIColor blackColor]; self.nameLabel.font=[UIFont bol…
UITabBarController下面常常需要为多个ViewController设置导航栏样式,总结了一下遇到过的为UINavigationBar添加背景图片的几种简单思路 以设置背景图片为例: 第一种,直接在视图里面单独设置每个视图的UINavigationBar,适合每个页面需要不同的导航栏样式. [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bg_all-64&q…