可能重复:
如何创建多行UITextfield?
如何实现多行文本字段,就像我在iPhone消息应用程序中看到的那样?

看起来一旦输入长度超过长度,就会自动创建第二行.
编辑:更新以澄清我在使用UITextView时遇到的挑战
对我来说,我想将UITextView的感觉和外观建模为如下所示.我不知道如何按照建议使用UITextView.例如
1)如果我的文本需要溢出到下一行,如何动态展开框
2)如何添加边框和样式,如下所示
3)如何在键盘正上方(而不是在视图中)附加文本框
我知道Instagram也有这个,如果有人可以指出我正确的方向,这将是伟大的.谢谢你

我正在使用UIImagePickerController为我的应用程序选择图像.然而,我在维持所选图像的纵横比方面面临一些挑战
例如,
我手机上的原始图像如下(非方形图像):

通过"移动和缩放"页面在iphone上选择图像以裁剪图像后,结果如下:(此处仍保持宽高比)

我的应用程序将在带有方框(200 x 200)的UIImageView中显示所选图像.将所选图像设置为UIImageView(UIImageView.image = selectedImage)后,图像的宽高比不会保持,而是跟随UIImageView的框架:(图像看起来在我的UIImageView中现在倾斜):

在这种情况下,有没有办法保持图像的纵横比?
编辑:更新预期结果
经过一番思考,我意识到解决我的问题的最好方法是确保对于这样的图像(非正方形),我需要将它们"转换"成方形图像,即填充图像顶部和底部的空白区域以制作广场例如
预期图片:(添加了顶部和底部边框)

编辑:使用示例代码更新
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
self.imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
//Compress image
UIImage *image = [self scaleImage:img toSize:CGSizeMake(612.0,612.0)];
self.imageData = UIImageJPEGRepresentation(image, 0.75);
}
Run Code Online (Sandbox Code Playgroud)
通过添加代码"self.imageView.contentMode = UIViewContentModeScaleAspectFill;",我能够在uiimageview中获取方形图像

但似乎原始图像仍然不是方形图像,因此当我执行"UIImage*image = [self scaleImage:img toSize:CGSizeMake(612.0,612.0)];"时,仍会出现偏斜问题.我的假设是否正确?无论如何要缓解这个问题,因为我仍然需要在应用程序的其他地方显示"压缩"图像.
是否有一种方法来检索标签栏控制器的当前可见导航控制器?
例如,我的程序中有两个标签栏(每个导航控制器一个),如下所示
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//Method is called when user clicks on a hyperlink in one of view controllers
NSDictionary *dict = [self parseQueryString:[url query]];
NSString *userID = [dict objectForKey:@"id"];
NSString *navconTitle = [dict objectForKey:@"navcon"];
//intention is to push a view controller onto the CURRENT navigation stack
[navcon pushViewController:someViewController animated:YES];
}
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何确定当前的导航控制器,以便我可以将更多的viewcontrollers推到它上面?
在向核心数据模型添加2个附加字段后,我遇到了以下错误.
CarPark_CarPark_ was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object.
Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger.
Here's the current observation info:
<NSKeyValueObservationInfo 0x1b6510> (
<NSKeyValueObservance 0x19b210: Observer: 0x1a8cf0, Key path: coordinate,
Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0x1b7e00>
)
Run Code Online (Sandbox Code Playgroud)
我对下一步做什么有点迷茫.任何有关这方面的指导将非常感谢!请让我知道还需要哪些其他信息.
如何在UIViewController中执行以下操作(包含tableview作为子视图)
我最初有一个UIViewController显示预览部分(UIView)
//Setup container for preview section
UIView *tempContainer = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 320, 100)];
self.preview_answer_container = tempContainer;
self.preview_answer_container.backgroundColor = [UIColor clearColor];
[tempContainer release];
[self.view addSubview:self.preview_answer_container];
Run Code Online (Sandbox Code Playgroud)
我还在下面添加了一个UITableView(和一个搜索栏)
//setup tableview
UITableView *tempTable = [[UITableView alloc]initWithFrame:CGRectMake(0,44 ,320,self.view.frame.size.height - 44)];
self.tagFriendsTableView = tempTable;
self.tagFriendsTableView.delegate = self;
self.tagFriendsTableView.dataSource = self;
[tempTable release];
[self.view addSubview:self.tagFriendsTableView];
Run Code Online (Sandbox Code Playgroud)

使用此设置,我的滚动区域很小(仅预览部分下方的静态区域)
如何修改我的代码,以便1)我可以向上滚动整个页面,即预览部分和tableview将向上滚动2)当搜索栏到达顶部(导航栏下方)时,滚动整体将停止(参见屏幕截图),但UITableView中的内容仍然是可滚动的

编辑:
添加了UIScroll视图的代码.但是,对我来说没有任何改变.我的代码出了什么问题?
//setup scroll view
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//Search
UISearchBar *tempBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 120 + 20, 320, 44)];
self.sBar = tempBar; …Run Code Online (Sandbox Code Playgroud) 我正在通过以下行为为我的应用程序实施APNS推送
1)如果应用程序未激活,即在后台或尚未启动:
用户将收到弹出消息,点击后会将他/她带到应用程序的第3个标签页(参见下面的代码)
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
self.tabController.selectedIndex = 3;
}
Run Code Online (Sandbox Code Playgroud)
2)如果应用程序已启动且当前处于活动状态
将不会显示弹出警报,并且新通知的数量将在第3个选项卡上显示为数字

我的问题是如何确定用户的应用程序是否处于活动状态?如何以及在何处实施检查以便我可以设置2种不同的行为?
任何人都可以告诉我如何更改导航栏下方的边框?

我想将它从当前的黑光改为更柔和的颜色.感谢这里的任何帮助
我正在创建一个UIButton的子类,以创建我自己的自定义按钮.我的代码如下:
//interface file (subclass of uIButton
@interface UICustomButton : UIButton
{
Answer *answer;
NSString *btnType;
}
@property (nonatomic, retain) Answer *answer;
@property (nonatomic, assign) NSString *btnType;
- (id)initWithAnswer:(Answer *)ans andButtonType:(NSString *)type andFrame:(CGRect)frame;
- (void)buttonPressed;
@end
//Implementation file (.m)
@implementation UICustomButton
@synthesize answer,btnType;
- (id)initWithAnswer:(Answer *)ans andButtonType:(NSString *)type andFrame:(CGRect)frame;
{
self = [super initWithFrame:frame];
if (self)
{
self = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
self.backgroundColor = [UIColor colorWithHexString:@"#E2E4E7"];
}
[self addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlStateNormal];
self.answer = ans;
self.btnType = type;
return self; …Run Code Online (Sandbox Code Playgroud) 我通过以下代码更改了导航栏颜色
navconFvc.navigationBar.tintColor = [UIColor colorWithHexString:@"faf6f5"];
Run Code Online (Sandbox Code Playgroud)
代码工作但文本颜色也需要更改(见下面的截图).此外,右侧的刷新按钮徽标也会受到影响

如果我导航到堆栈中的另一个页面,则会出现同样的问题

问题:如何更改颜色
我改变了导航栏的背景颜色后?
任何人在尝试使用图像选择器访问照片库之前遇到此错误?
NSInvalidArgumentException Cannot set metadata in read-only store.
Run Code Online (Sandbox Code Playgroud)
任何关于实际出错的建议以及如何解决这个问题的建议将不胜感激.
错误堆栈的快照如下所示

ios ×10
objective-c ×9
aspect-ratio ×1
border ×1
core-data ×1
icons ×1
iphone ×1
photolibrary ×1
scroll ×1
textcolor ×1
uibutton ×1
uiscrollview ×1
uitableview ×1
uitextfield ×1