我试图UIButton在其titleLabel中创建一个包含两行文本的文本.这是我正在使用的代码:
UIButton *titleButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)];
titleButton.titleLabel.font = [UIFont boldSystemFontOfSize:24.0];
[titleButton setTitle:@"This text is very long and should get truncated at the end of the second line" forState:UIControlStateNormal];
titleButton.titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
titleButton.titleLabel.numberOfLines = 2;
[self addSubview:titleButton];
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,文本只出现在一行上.似乎实现多行文本的唯一方法UIButton.titleLabel是设置numberOfLines=0和使用UILineBreakModeWordWrap.但这并不能保证文本正好是两行.
UILabel但是,使用plain 可以工作:
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)];
titleLabel.font = [UIFont boldSystemFontOfSize:24.0];
titleLabel.text = @"This text is very long and should get truncated at the end of …Run Code Online (Sandbox Code Playgroud) 我UIImageView根据用户交互加载了一个图像.最初显示父视图时,未选择任何图像且图像视图为黑色.如果用户离开该视图并返回,则图像仍然存在.我试过了
myImageView.image = nil;
Run Code Online (Sandbox Code Playgroud)
离开视图但图像仍然存在.如何删除图像以使其UIImageView再次显示为黑色?
该
的UIImageView
通过IB连接.
我的iPhone应用程序中有各种视图需要填充,例如左边是文本对齐的自定义UIButton,背景颜色为UILabel.
这可能是一个非常愚蠢的问题,但我如何应用'填充'来移动左边的文本?
我已经厌倦了使用边界等没有任何成功.
我知道我可以UILabel用背景颜色为我创建一个包装器视图,但它看起来有点矫枉过正.
非常感谢.
我有一个目前提供六项的UICollectionView设置UICollectionViewDataSource.这些比填充屏幕所需的少.问题是我的集合视图仅在有足够的项目填充屏幕时滚动(用10,20测试).当显示较少的项目时,它甚至不会做我试图获得的反弹动画,它只是修复.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCollectionViewData) name:UIDocumentStateChangedNotification object:nil];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.itemSize = CGSizeMake(160, 100);
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 0;
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.bounces = YES;
[self.view addSubview:self.collectionView];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.collectionViewData count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Expense *expense = [self.collectionViewData objectAtIndex:indexPath.row];
UILabel …Run Code Online (Sandbox Code Playgroud) 由于UIProgressHUD需要访问私有api,所以我希望构建一个UIView带圆角和白色边框.我知道要转角是:
view.layer.cornerRadius = 5;
Run Code Online (Sandbox Code Playgroud)
但是如何让uiview同时具有圆角和白色边框?
欢迎任何评论
谢谢interdev
我选择使用UITableViewController没有笔尖的.我需要一个底部带有两个按钮的UIToolbar.这样做最简单的方法是什么?
PS我知道我可以轻松地使用a UIViewController并添加一个UITableView但是我希望在应用程序中看起来一致.
有人可以帮忙吗?
我看到了以下示例,我不确定其有效性:
(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Initialize the toolbar
toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleDefault;
//Set the toolbar to fit the width of the app.
[toolbar sizeToFit];
//Caclulate the height of the toolbar
CGFloat toolbarHeight = [toolbar frame].size.height;
//Get the bounds of the parent view
CGRect rootViewBounds = self.parentViewController.view.bounds;
//Get the height of the parent view.
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
//Get the width of the parent view,
CGFloat rootViewWidth = …Run Code Online (Sandbox Code Playgroud) 如何将变量传递给UIAlertView委托?
我有一个我想在警报视图委托中使用的变量.它仅用于显示UIAlertView和UIAlertView委托的函数,因此我认为它不应该是控制器上的属性.有没有办法将变量附加到UIAlertView委托中并在委托中检索它?
- (void) someUserCondition:(SOCode *)userCode {
if ([userCode warrentsConfirmation] > 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Are you sure?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
[alert setAlertViewStyle:UIAlertViewStyleDefault];
//TODO somehow store the code variable on the alert view
[alert show];
}
}
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"OK"]){
SOCode *userCode = //TODO somehow get the code from the alert view
[self continueWithCode:code];
}
}
Run Code Online (Sandbox Code Playgroud) 我试图UIActivityViewController用一个长NSString的数据作为数据.如果我输入一个> 140个字符的字符串,则其中的推文表格不会显示该字符串.如果我在将字符串提供给控制器之前将UIActivities其截断,则所有字符串都会被截断.我不希望Facebook或消息被截断.
有没有办法给不同的字符串UIActivities?
谢谢!
(例如,Marco Arment的The Magazine应用程序通过截断字符串后跟@TheMagazineApp进行此操作UIActivityPostToTwitter,以及其他内容UIActivities.)
我有UIPickerView3个组件填充2 NSMutableArrays(2个组件具有相同的阵列).
一个教程说:
//PickerViewController.m
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"Selected Color: %@. Index of selected color: %i", [arrayColors objectAtIndex:row], row);
}
Run Code Online (Sandbox Code Playgroud)
但我希望UIAlertView 在用户触摸UIButton后显示每个组件的选定行.
有没有办法做到这一点?或者我必须使用3隐形UILabels作为缓冲区?
提前致谢.
我正在开发适用于Windows 8.1和Windows Phone 8.1的Unified健身应用.理想情况下,其中一个核心视图将包含每日进度表.问题是我无法想出实际的仪表或仪表.我想要的只是一个径向进度条或类似于Windows Phone商店中常见电池应用中的电池电量表/米的东西.据我所知,WPF/VS 2013不提供开箱即用的这种组件.我知道Telerik和其他一些第三方提供类似的东西,但我更喜欢使用开源的东西或自己构建它.
有没有人知道与.NET 4.5和WPF一起使用的较新的开源组件,或者有关于如何构建自己的组件的示例?
到目前为止,我发现的与此链接类似:WPF的量表
但我希望使用类似的东西: 
iphone ×7
ios ×5
objective-c ×4
cocoa-touch ×2
uibutton ×2
uilabel ×2
.net-4.5 ×1
c# ×1
ios6 ×1
padding ×1
uialertview ×1
uiimage ×1
uiimageview ×1
uipickerview ×1
uitableview ×1
uitoolbar ×1
uiview ×1
windows-8.1 ×1
wpf ×1