IOS开发中,为什么图片拖入VIEW中,长度和ios 宽度自适应都要除以2?

iOS 问题:在一个Controlleview拖一个UIimageView,让其显示照片,怎么才能让它在不同尺寸的手机上自动适应屏幕大小。就是填满屏幕。求大神指导 -
在一个Controlleview拖一个UIimageView,让其显示照片,怎么才能让它在不同尺寸的手机上自动适应屏幕大小。就是填满屏幕。求大神指导
共有 3 个回答
你可以设置UIImageview的属性来达到目的
登录后方可回复
@左耳钉 : 大神,请讲仔细点。我是小白。谢谢。
登录后方可回复
用一段代码自动获取屏幕尺寸。
登录后方可回复
登录后方可回答
耗时 0.0648 秒下次自动登录
现在的位置:
& 综合 & 正文
IOS开发中UITableView和UITableViewCell的几种样式
转载自:/page/M0/S816/816152.html
说了好久要写本身的技巧博客,因为履行力差,一向拖到如今才开端写。我是一个刚进入软件行业还不到一年的小菜鸟,没有什么技巧可言,然后就在这里大胆妄自负大的在博客园上写些器材,还欲望技巧大牛们不要嘲笑。我写此博客的目标是想经由过程这些跟大师交换技巧,跟一些也像我一样刚进入软件行业的伴侣一点参考。文章里有什么错误迎接大师可以或许给我批驳指出,今后我会加倍尽力,学好技巧跟大师分享。固然内容技巧含量不高,然则请尊敬劳动成果。若是转载引用,欲望注名出处和原文链接。
今天要分享的是IOS开辟中一个应用率很是高的一个控件-------UITableView,这两天正在应用tableview做信息的显示,在写时对tableview和tableviewcell的几种样式一向分不清楚,今天我具体的研究了一下,下面就跟大师分享一下:
一、体系本身的UITableView样式有两种:
1.UITableViewStylePlain:
Plain样式的是方形的,充斥你给的view.frame坐标。
2.UITableViewStyleGrouped:
Grouped样式主如果以圆角形显示。跟iphone自带的通信录编辑页面类似。
二、体系本身的UITableViewCell样式有四种:
1.UITableViewCellStyleDefault:
Default样式:左边一个显示图片的imageView,一个题目textLabel,没有detailTextLabel。
2.UITableViewCellStyleSubtitle:
Subtitle样式:左边一个显示图片的imageView,上边一个主题目textLabel,一个副题目detailTextLabel。主题目字体大且加黑,副题目字体小在主题面前目今边。
3.UITableViewCellStyleValue1:
Value1样式:左边一个显示图片的imageView,左边一个主题目textLabel,右边一个副题目detailTextLabel,主题目字体斗劲黑。
4.UITableViewCellStyleValue2:
Value2样式:左边一个主题目textLabel字体偏小,挨着右边一个副题目detailTextLabel,字体大且加黑。
That‘s all,Thank you for support。
&&&&推荐文章:
【上篇】【下篇】全部微信分类
当前位置:
本网站文章均来自网络,只以信息传播为目的,不代表认同其观点和立场,版权为原作者所有,请与公众号原作者联系。如有侵犯权益,或者不良信息。请立即联络我们删除!QQ:
TableView不显示没内容的Cell怎么办?类似这种,我不想让下面那些空的显示.很简单.self.tableView.tableFooterView = [[UIView alloc] init];加完这句之后就变成了这样.2 、自定义了leftBarbuttonItem左滑返回手势失效了怎么办?self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(onBack:)];self.navigationController.interactivePopGestureRecognizer.delegate = (id&uigesturerecognizerdelegate&)3、ScrollView莫名其妙不能在viewController划到顶怎么办?self.automaticallyAdjustsScrollViewInsets = NO;4、键盘事件写的好烦躁,都想摔键盘了,怎么办?
使用IQKeyboardManager(github上可搜索5、为什么我的app老是不流畅,到底哪里出了问题?如图这个神器叫做:KMCGeigerCounter,快去github搬运吧.6、怎么在不新建一个Cell的情况下调整separaLine的位置?_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);7、怎么点击self.view就让键盘收起,需要添加一个tapGestures么?- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];}8、怎么给每个ViewController设定默认的背景图片?
使用基类啊,少年。9、想在代码里改在xib里添加的layoutAttributes,但是怎么用代码找啊?
像拉button一样的拉你的约束.nslayoutattribute也是可以拉线的.10、怎么像safari一样滑动的时候隐藏navigationbar?navigationController.hidesBarsOnSwipe = Y11、导航条返回键带的title太讨厌了,怎么让它消失![[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];12、CoreData用起来好烦,语法又臭又长,怎么办? 使用 MagicRecord13、CollectionView 怎么实现tableview那种悬停的header?使用 CSStickyHeaderFlowLayou14、能不能只用一个pan手势来代替UISwipegesture的各个方向?- (void)pan:(UIPanGestureRecognizer *)sender{typedef NS_ENUM(NSUInteger, UIPanGestureRecognizerDirection) {
UIPanGestureRecognizerDirectionUndefined,
UIPanGestureRecognizerDirectionUp,
UIPanGestureRecognizerDirectionDown,
UIPanGestureRecognizerDirectionLeft,
UIPanGestureRecognizerDirectionRight};static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUswitch (sender.state) {
case UIGestureRecognizerStateBegan: {
if (direction == UIPanGestureRecognizerDirectionUndefined) {
CGPoint velocity = [sender velocityInView:recognizer.view];
BOOL isVerticalGesture = fabs(velocity.y) & fabs(velocity.x);
if (isVerticalGesture) {
if (velocity.y & 0) {
direction = UIPanGestureRecognizerDirectionD
direction = UIPanGestureRecognizerDirectionUp;
if (velocity.x & 0) {
direction = UIPanGestureRecognizerDirectionR
direction = UIPanGestureRecognizerDirectionL
case UIGestureRecognizerStateChanged: {
switch (direction) {
case UIPanGestureRecognizerDirectionUp: {
[self handleUpwardsGesture:sender];
case UIPanGestureRecognizerDirectionDown: {
[self handleDownwardsGesture:sender];
case UIPanGestureRecognizerDirectionLeft: {
[self handleLeftGesture:sender];
case UIPanGestureRecognizerDirectionRight: {
[self handleRightGesture:sender];
default: {
case UIGestureRecognizerStateEnded: {
direction = UIPanGestureRecognizerDirectionU
default:}}15、拉伸图片的时候怎么才能让图片不变形?1)UIImage *image = [[UIImage imageNamed:@&xxx&] stretchableImageWithLeftCapWidth:10 topCapHeight:10];2)16、怎么播放GIF的时候这么卡,有没有好点的库?FlipBoard出品的太适合你了:/Flipboard/FLAnimatedImage17、怎么一句话添加上拉刷新?/samvermette/SVPullToRefresh[tableView addPullToRefreshWithActionHandler:^{
// prepend data to dataSource, insert cells at top of table view
// call [tableView.pullToRefreshView stopAnimating] when done} position:SVPullToRefreshPositionBottom];18、怎么把tableview里cell的小对勾的颜色改成别的颜色?_mTableView.tintColor = [UIColor redColor];19、本来我的statusbar是lightcontent的,结果用UIImagePickerController会导致我的statusbar的样式变成黑色,怎么办?- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];}20、怎么把我的navigationbar弄成透明的而不是带模糊的效果?[self.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];self.navigationBar.shadowImage = [UIImage new];self.navigationBar.translucent = YES;21、怎么改变uitextfield placeholder的颜色和位置?继承uitextfield,重写这个方法- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];}
上一篇:第一篇
下一篇:最后一篇
关注排行榜
妈妈宝贝-育儿知识精选
美容护肤达人
去购物返利网
小女的笑话
友情链接:iOS开发UI篇—UIScrollView控件实现图片轮播 - 文顶顶 - 博客园
iOS开发UI篇&UIScrollView控件实现图片轮播
一、实现效果
实现图片的自动轮播
& & & & &&
二、实现代码
storyboard中布局
1 #import "YYViewController.h"
3 @interface YYViewController () &UIScrollViewDelegate&
4 @property (weak, nonatomic) IBOutlet UIScrollView *
8 @property (weak, nonatomic) IBOutlet UIPageControl *pageC
10 @property (nonatomic, strong) NSTimer *
13 @implementation YYViewController
15 - (void)viewDidLoad
[super viewDidLoad];
CGFloat imageW = self.scrollview.frame.size.
CGFloat imageW = 300;
CGFloat imageH = self.scrollview.frame.size.
CGFloat imageY = 0;
NSInteger totalCount = 5;
1.添加5张图片
for (int i = 0; i & totalC i++) {
UIImageView *imageView = [[UIImageView alloc] init];
CGFloat imageX = i * imageW;
imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
NSString *name = [NSString stringWithFormat:@"img_0%d", i + 1];
imageView.image = [UIImage imageNamed:name];
隐藏指示条
self.scrollview.showsHorizontalScrollIndicator = NO;
[self.scrollview addSubview:imageView];
2.设置scrollview的滚动范围
CGFloat contentW = totalCount *imageW;
//不允许在垂直方向上进行滚动
self.scrollview.contentSize = CGSizeMake(contentW, 0);
3.设置分页
self.scrollview.pagingEnabled = YES;
4.监听scrollview的滚动
self.scrollview.delegate =
[self addTimer];
58 - (void)nextImage
int page = (int)self.pageControl.currentP
if (page == 4) {
滚动scrollview
CGFloat x = page * self.scrollview.frame.size.
self.scrollview.contentOffset = CGPointMake(x, 0);
73 // scrollview滚动的时候调用
74 - (void)scrollViewDidScroll:(UIScrollView *)scrollView
NSLog(@"滚动中");
页码 = (contentoffset.x + scrollView一半宽度)/scrollView宽度
CGFloat scrollviewW =
scrollView.frame.size.
CGFloat x = scrollView.contentOffset.x;
int page = (x + scrollviewW / 2) /
scrollviewW;
self.pageControl.currentPage =
85 // 开始拖拽的时候调用
86 - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
关闭定时器(注意点; 定时器一旦被关闭,无法再开启)
[self.timer invalidate];
[self removeTimer];
93 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
开启定时器
[self addTimer];
开启定时器
102 - (void)addTimer{
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
关闭定时器
110 - (void)removeTimer
[self.timer invalidate];
提示:以下两个属性已经和storyboard中的控件进行了连线。
@property (weak, nonatomic) IBOutletUIScrollView *
@property (weak, nonatomic) IBOutletUIPageControl *pageC
补充:定时器NSTimer
& &定时器 适合用来隔一段时间做一些间隔比较长的操作
&NSTimeInterval:多长多件操作一次
&target :操作谁
&selector : 要操作的方法
&userInfo: 传递参数
&repeats: 是否重复
& self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
随笔 - 278
评论 - 546主题 : UIImageview根据里面的图片及文字内容自动变换大小
级别: 侠客
可可豆: 1191 CB
威望: 1191 点
在线时间: 384(时)
发自: Web Page
UIImageview根据里面的图片及文字内容自动变换大小&&&
小弟现在遇到的情况如下:UIImageView里  imageview.setimage=@'dsdsd.png';加了一张图片,但是现在想在在加一张imagview.addsubview:就不行 另把这个图片放到一个view中  *****mageview addsubview:view 也不行。。。纠结主要问题是:我想要实现imageview随着里面图片,主要是lable的text内容大小,来变换imageview的大小 但是一直没实现纠结一天了,求高手帮忙纠结。。。p.p1 {margin: 0.0px 0.0px 0.0px 0.0 font: 10.0px M color: #ff2c38}p.p2 {margin: 0.0px 0.0px 0.0px 0.0 font: 10.0px M color: #00a0ff}p.p3 {margin: 0.0px 0.0px 0.0px 0.0 font: 10.0px M color: # min-height: 14.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0 font: 10.0px M color: #41cc45}p.p5 {margin: 0.0px 0.0px 0.0px 0.0 font: 10.0px M color: #ffffff}p.p6 {margin: 0.0px 0.0px 0.0px 0.0 font: 10.0px M color: #23ff83}p.p7 {margin: 0.0px 0.0px 0.0px 0.0 font: 10.0px M color: #41cc45; min-height: 14.0px}span.s1 {color: #00a0ff}span.s2 {color: #ffffff}span.s3 {color: #d31895}span.s4 {color: #786dff}span.s5 {color: #23ff83}span.s6 {color: #ff2c38}span.Apple-tab-span {white-space:pre}NSURL *url = [NSURL URLWithString:@&/blog/developer/icon/weiboair_logo_2.jpg&];&&NSData *data = [NSData dataWithContentsOfURL:url];&&&&UIImage *imgs=[UIImage imageWithData:data];&&//UIView *testview=[UIView initWithFrame:CGRectMake(0.0f, 15.0f,20.0 , 20.0)];&&//[testview addSubview:imgs];&&//[imageview addSubview:testview];&&UIImage *img=[UIImage imageNamed:@&PopoverBottomArrowRight.png&];&&float xregion=[touch locationInView:self.view].x-66.0f/2-5;&&float yregion=[touch locationInView:self.view].y-76.6f;&&imageview = [[UIImageView alloc] init];&&imageview.frame=CGRectMake(xregion, yregion, 66.0f, 76.0f);&&imageview.contentMode=UIViewContentModeScaleToF&&imageview.tag=1;&&[imageview setImage:img];&&imageview.contentStretch=CGRectMake(xregion, xregion, 66.0f+20, 76.0f+20);&&NSString *title = [NSString stringWithFormat:@&dsdsdsddsdsdsddsdsdsdsd&];&&&&CGSize titleHeight = [title sizeWithFont:[UIFont fontWithName:@&Helvetica& size:12.0f] &&&&&&&&  constrainedToSize:CGSizeMake(25, 250)&&&&&&&&   lineBreakMode:UILineBreakModeCharacterWrap];&&&&UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(22, 15,titleHeight.width, 35.0f)];&&&&[label setText:title];&&label.textColor = [UIColor redColor];&&label.font = [UIFont systemFontOfSize:8.0];&&&&label.lineBreakMode=UILineBreakModeWordW&&label.numberOfLines=0;//&&label.adjustsFontSizeToFitWidth=YES;//&&if(label.numberOfLines&2)//&&{//&& NSString *str= [NSString stringWithFormat:@&%@%@&, title, @&....&];//&& label.numberOfLines=0;//&& [label setText:str];//&&}//&&else//&&{//&&[label setText:title];//&&}&&//&&imageview.clipsToBounds=YES;&&[imageview addSubview:label];&&[label release];&&&&imageview.userInteractionEnabled=YES;&&/*     useless in iphone sdk 3.2,at least 4.0 &&imageview.layer.shadowColor=[UIColor blackColor].CGC&&imageview.userInteractionEnabled=YES;&&imageview.layer.shadowOpacity=0.5;&&imageview.layer.shadowOffset = CGSizeMake(5,3);&&&&imageview.layer.shadowColor =  [UIColor blueColor].CGC&&&&*/&&UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];&&[button addTarget:self action:@selector(btntest:) forControlEvents:UIControlEventTouchUpInside];&&button.frame = CGRectMake(45.0f, 20.0f, 13.0f, 20.0f);&&[button setTitle:@&test& forState:UIControlStateNormal];&&[imageview addSubview:button]; //&&[UIView beginAnimations:@&Curl& context:nil];//&&//[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//&&[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];//&&[UIView setAnimationDuration:0.6];//&&//&&[imageview setFrame:CGRectMake(xregion, self.view.frame.size.height/2, self.view.frame.size.width/3, 50.0)];//&&//&&[UIView commitAnimations];&&//[self.view addSubview:imgview];&&[self.view addSubview:imageview];
级别: 侠客
可可豆: 1191 CB
威望: 1191 点
在线时间: 384(时)
发自: Web Page
自己顶下,最上面的那些乱七八糟的没用 。。NSURL *url = [NSURL URLWithString:@&/blog/developer/icon/weiboair_logo_2.jpg&];&&NSData *data = [NSData dataWithContentsOfURL:url];&&从这里开始 期望高手中 - - 。。
级别: 侠客
可可豆: 1191 CB
威望: 1191 点
在线时间: 384(时)
发自: Web Page
再顶- -&&
级别: 精灵王
UID: 52331
发帖: 1409
可可豆: 2374 CB
威望: 10092 点
在线时间: 1080(时)
发自: Web Page
帮顶! 请问lz是生得么 我也是啊!!
特别能吃苦”这5个字,我想了想,我只做到了前四个。
级别: 侠客
可可豆: 1191 CB
威望: 1191 点
在线时间: 384(时)
发自: Web Page
回 3楼(cao_ya_dong) 的帖子
是的&&谢过
关注本帖(如果有新回复会站内信通知您)
论坛技术问题应该发布到? 正确答案:CocoaChina问答
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版}

我要回帖

更多关于 ios 屏幕宽度 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信