如何在HTML段落标记中放置块元素?当我尝试这样做时,Firebug的HTML选项卡显示段落不包含块元素.此外,应用于该段落的任何CSS都不适用于子块元素.
这段代码:
<p>
<ol>
<li>foo</li>
<li>bar</li>
</ol>
</p>
p {
line-height: 2em;
}
Run Code Online (Sandbox Code Playgroud)
变为:
<p></p>
<ol>
<li>foo</li>
<li>bar</li>
</ol>
Run Code Online (Sandbox Code Playgroud) 在一个UITableViewCell与UITableViewCellStyleSubtitle造型,我设置的imageView.image,textLabel.text和detailTextLabel.text.电池周围有白色衬垫.如何摆脱填充,以便我的所有图像都像下面的Youtube应用程序一样互相触摸?

我想使用Perl正则表达式来匹配这样的字符串:
spaM
s p a m
sp Am
S p a m
Run Code Online (Sandbox Code Playgroud)
看看Perl的x修饰符,我应该能够这样做:
<?php
echo preg_match('#spam#ix', 's p a m');
?>
Run Code Online (Sandbox Code Playgroud)
但这打印出0(假).该x修改实际上忽略了对正则表达式的空白,不被分析的字符串.我怎么会这样做呢?也就是说,忽略正在分析的字符串上的空格而不是我的正则表达式?我知道有多步骤方法可以做到这一点,例如首先从字符串中剥离所有空白区域,但我想知道是否有强大的一步法正则表达式解决方案.
假设我有一个盒子。填充是渐变,并且笔划的厚度为1像素。我如何调整其填充大小,但保持笔触厚度不变?
private function resizeMovieClip(newWidth:Number, newHeight:Number):void
{
this.movieClip.width = newWidth;
this.movieClip.height = newHeight;
}
Run Code Online (Sandbox Code Playgroud)
基本上,我想模拟Javascript对DOM元素的大小调整。在JS中,调整框的大小永远不会改变其边框。
我在两个UILabel中显示用户注释- 一个用于用户名,另一个用于消息.两个标签都具有相同的X,Y坐标,但消息标签前面的空格等于用户名的宽度.这种技术可以帮助我轻松支持多行消息.
用户编写阿拉伯语消息时会出现问题.阿拉伯语是一种从左到右的语言.这意味着,我必须在阿拉伯字符串的末尾添加空格,而不是开头.正如您在下面的屏幕截图中看到的那样,我没有做出这种区分,并且阿拉伯语消息遇到了用户名.那么如何检测到UILabel 的文本属性(NSString)是用从右到左的语言编写的呢?

我尝试使用正则表达式,但以下函数始终为每个字符串返回false,包括阿拉伯语.
@implementation UILabel (position)
- (BOOL) containsArabic
{
NSError* error;
NSRegularExpression* regex = [NSRegularExpression
regularExpressionWithPattern:@"\p{Arabic}"
options:0
error:&error
];
return error == nil
&& [regex
numberOfMatchesInString:self.text
options:0
range:NSMakeRange(0, self.text.length)] > 0;
}
@end
Run Code Online (Sandbox Code Playgroud)
- (BOOL) containsArabic
{
NSString *isoLangCode = (NSString*)CFStringTokenizerCopyBestStringLanguage(
(CFStringRef)self.text,
CFRangeMake(
0,
self.text.length
)
);
NSLocaleLanguageDirection direction = [NSLocale lineDirectionForLanguage:isoLangCode];
NSLog(@"++++++");
NSLog(@"%@", self.text);
NSLog(@"%d", direction);
return direction == NSLocaleLanguageDirectionRightToLeft;
}
Run Code Online (Sandbox Code Playgroud)
输出无用:
2012-05-28 10:59:11.454 [2110:707] MANCHESTER …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一种算法,用于查找最接近的值的索引,该索引小于或等于排序数组中的搜索值.在数组[10,20,30]的示例中,以下搜索值应输出以下索引:
我想使用二进制搜索进行对数运行时.我有一个C-esque伪代码的算法,但它有3个基本情况.这3个基本案例是否可以压缩为1以获得更优雅的解决方案?
int function indexOfClosestLesser(array, searchValue, startIndex, endIndex) {
if (startIndex == endIndex) {
if (searchValue >= array[startIndex]) {
return startIndex;
} else {
return -1;
}
}
// In the simplistic case of searching for 2 in [0, 2], the midIndex
// is always 0 due to int truncation. These checks are to avoid recursing
// infinitely from index 0 to index 1.
if (startIndex == endIndex - 1) {
if (searchValue >= …Run Code Online (Sandbox Code Playgroud) 在layoutSubviews的文档中,Apple说:
您不应该直接调用此方法.
我正在努力实施sizeToFit.我希望它在所有子视图上放置一个紧密的边界框.我必须在确定这样的边界框之前布局子视图.这意味着我必须打电话layoutSubviews,苹果皱眉.如何在不违反Apple规则的情况下解决这一难题?
- (void)layoutSubviews
{
[super layoutSubviews];
self.view0.frame = something;
self.view1.frame = somethingElse;
}
- (void)sizeToFit
{
[self layoutSubviews];
self.frame = CGRectMake(
self.frame.origin.x,
self.frame.origin.y,
MAX(
self.view0.frame.origin.x + self.view0.frame.size.width,
self.view1.frame.origin.x + self.view1.frame.size.width
),
MAX(
self.view0.frame.origin.y + self.view0.frame.size.height,
self.view1.frame.origin.y + self.view1.frame.size.height
)
);
}
Run Code Online (Sandbox Code Playgroud) 一个javascript库,比如Prototype,如何决定何时编写一个接受一系列参数的函数或者只接受一个巨大的对象?以下是两者的例子.每个人的利弊都很平衡,所以我不明白何时使用一种方法或另一种方法.
new Ajax.Request(
'server.php', {
onSuccess: function() {
console.info('I succeeded');
},
onFailure: function() {
console.info('I failed');
}
);
Run Code Online (Sandbox Code Playgroud)
优点:对象中的参数顺序无关紧要.当您忘记参数的顺序时,您不必检查函数定义.此外,当其他人阅读该功能的调用时,他们会更好地了解您正在做的事情.想象一下,如果Ajax调用是这样的:
new Ajax.Request(
'server.php',
function() {
console.info('mystery function');
},
function() {
console.info('is this success or failure?');
}
);
Run Code Online (Sandbox Code Playgroud)
缺点:函数标题没有清楚地显示需要传递的内容.您被迫保持评论的最新状态.
// unclear what options need to be passed in without comments
Ajax = {
Request: function(url, options) {
}
};
// a little clearer
Ajax = {
Request: function(url, successCallback, failureCallback) {
}
};
Run Code Online (Sandbox Code Playgroud)
new PeriodicalExecuter(
function(myself) …Run Code Online (Sandbox Code Playgroud) 我正在查看Apple的懒惰表图像加载示例代码.我看到他们有两行开头@protocol ParseOperationDelegate.为什么他们两次这样做?我看过的关于Objective C协议的所有文档并没有告诉你两次这样做.
@class AppRecord;
@protocol ParseOperationDelegate;
//@interface ParseOperation : NSOperation <NSXMLParserDelegate>
@interface ParseOperation : NSOperation
{
@private
id <ParseOperationDelegate> delegate;
NSData *dataToParse;
NSMutableArray *workingArray;
//AppRecord *workingEntry;
//NSMutableString *workingPropertyString;
//NSArray *elementsToParse;
//BOOL storingCharacterData;
}
- (id)initWithData:(NSData *)data delegate:(id <ParseOperationDelegate>)theDelegate;
@end
@protocol ParseOperationDelegate
- (void)didFinishParsing:(NSArray *)appList;
- (void)parseErrorOccurred:(NSError *)error;
@end
Run Code Online (Sandbox Code Playgroud) 在操作我的一些NSString物体时,我得到了垃圾值.我认为问题源于我对NSString在基本级别的工作方式的误解.下面,我有一个对象,它有一个字符串指针作为合成属性.当我尝试直接将其注销时,编译器会给我一个警告,但它会注销我期望的值.在下一行,我尝试以正确的方式记录该字符串,但我最终得到了垃圾.
代码段
MyObject *object = [self.objects objectAtIndex:indexPath.row];
NSString *myString = object.myString;
NSLog(myString); // format not a string literal and no formal arguments
NSLog(@"formatted = %s", myString);
Run Code Online (Sandbox Code Playgroud)
产量
2011-05-16 13:06:51.137 MyProgram[917:207] thisValueIsGood
2011-05-16 13:06:51.138 MyProgram[917:207] formatted = `å
Run Code Online (Sandbox Code Playgroud)
这个问题已经滚雪球到其他使用这个最终字符串的函数上.当我将该字符串与其他字符串连接起来时,我会得到更多的垃圾.
objective-c ×4
cocoa-touch ×3
regex ×2
algorithm ×1
coding-style ×1
css ×1
flash ×1
html ×1
ios ×1
iphone ×1
javascript ×1
nsstring ×1
perl ×1
php ×1
protocols ×1
prototypejs ×1
search ×1
uiview ×1