NSTextBlock backgroundColor is not drawn - objective-c

I have an NSTextBlock subclass that has a specific backgroundColor set. Now when I add a custom paragraph style to a range of text like this
let block = MyTextBlock()
block.backgroundColor = myBackgroundColor
let pstyle = NSMutableParagraphStyle()
pstyle.textBlocks = [block]
attributedText.addAttribute(.paragraphStyle, value: pstyle, range: textRange)
// Append the attributed string to the text views textStorage ...
the text block is shown without a background color. I know that the text blocks works, because rectForLayout gets called, but when I try to override drawBackground it never gets called.
Do I have to do something else for NSTextBlocks to draw their background?
PS: Borders also seem to be ignored. I also tried to find a sample on Github, but that also doesn't draw any backgrounds, despite having a background color set.

After trying everything, I finally managed to get the background to show up, by setting
setValue(100, type: .percentageValueType, for: .width)
It seems that the drawing logic expects some value for the content size. Really nice documentation job there. This requirement is nowhere to be found.

Related

Why UICollectionView stops working when NSMutableAttributedString is set to one of its cells

I stumbled upon a special problem in my current project.
We have UICollectionView using a custom layout called SquareMosaicLayout.
Within this collection view the first cell it presenting a UITextView.
This text view again shall show an html text created with:
NSMutableAttributedString(fromHTMLString: htmlString, textColor: textColor, font: font)
Now when this string is assigned to the text view the collection view somehow stops working which means it does not ask the datasource for new cells when scrolling through the collection view.
This results in the collection view showing blank space.
Unfortunately I did not have time to isolate the problem in terms of if the custom layout breaks anything but it definitely has to do with assigning the string. If we don't do that the collection view works as expected.
We still did not found the reason for the behaviour but a first workaround.
It is possible to set the NSMutableAttributedString asynchronously.
extension UITextView {
[ ... ]
DispatchQueue.main.async {
let optionalAttributedText = NSMutableAttributedString(fromHTMLString: htmlString, textColor: self.textColor, font: self.font)
guard let attributedText = optionalAttributedText else { return }
self.attributedText = attributedText
[ ... ]
In that case the UICollectionView behaves normal showing all the cells.

Appcelerator: How to create Ti.UI.TextArea dynamically adjusting to content but with minimal height

I want to create a Ti.UI.TextArea object which would dynamically adjust its height to content but would have default height set (if no content). In Appcelerator if you don't specify height then it will automatically adjust its size to content but if there is no text then its size will be similar to textField. This is to small for me.
If you specify height property, then TextArea height won't change even if text will be longer than editable region.
I would like to have something like this:
var textArea = Ti.UI.createTextArea({
minHeight: 30,
});
or like this:
var textArea = Ti.UI.createTextArea({
minLines: 3,
});
I am looking for solution both for Android and iOS.
Is there any workaround for that?
You can change the height of the textField dynamically.
Add onChange event handler and change the height of the textField dynamically according to the number of lines in the text field.
Starting with 7.5.0.GA you can use maxLines on Android to be able to extend the TextArea to when pressing return. For iOS you have to create a work-around since there is no parity at the moment.

Vuejs: vue-color is not changing picker location if linked v-model value is changed

I am using Sketch option of vue-color for color picking. It uses v-model to communicate color change as follows:
<sketch-picker v-model="colors" />
where colors is a data initialised as below:
colors: {hex: "#c0392b", a: 1}
When page is loaded color-picker is at expected position i.e. (hex: #c0392b). On changing picker position, colors value changed as expected.
Issue comes when I change colors value in a method like below:
this.colors.hex = "#ff00ff";
this.colors.a = 0.5;
In this case even though data colors value is changed(this is confirmed), color-picker is still pointing at old location i.e. #c0392b.
I don't think this is an expected behavior and possibly a bug. What should be way-around this issue?
Detecting changes in objects is a bit nuanced in Vue/JavaScript. See https://v2.vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats and the deep option of watch https://v2.vuejs.org/v2/api/#vm-watch
You may simply need to use
this.colors = Object.assign({}, this.colors, { a: 0.5, hex: "#ff00ff" })

monotouch dialog cell sizing and section caption color

I am using monotouch dialog to generate a view. I managed to change the background color by subclassing DialogViewController, but the contrast with the section caption makes the text hard to read. How do I change the section caption color?
I am also using a StyledStringElement as a button in the same view. I cant seem to figure out how to shrink this element so that it looks more like a button. Please provide examples. Your help is appreciated.
To solve this issue I used a glassbutton with the it's HandleTapped handler as below.
var butt = new GlassButton(new RectangleF(80,150,150,50))
{
Font = UIFont.BoldSystemFontOfSize(22),
NormalColor = UIColor.Red,
};
void HandleTapped (GlassButton obj)
{
}
as for the colors, I used miguel's solution here. Hope this helps someone down the road.

How to implement this using Windows forms?

I have two problems with my windows form in Visual Basic .NET 2008. If you have worked with sticky notes you will understand me better.
Now my problems:
If you look you'll see the background color of number 1 and 2 are
diffrent but both belongs to the same control. How is this possible?
In right bottom corner, there is something by which a user can resize the form.
How I can do this?
Item 1: I think you are referring to LinearGradient Brush-- look in the System.Drawing.Drawing2D class.
Item 2: They are drawing a resize handler. You can try using the ControlPaint.DrawSizeGrip method or draw your own.
Update:
Per your comments, you can look into Owner-drawing a Windows.Forms TextBox
You can draw a gradient background by overriding OnPaintBackground():
protected override void OnPaintBackground(PaintEventArgs e)
{
// set these to whatever you want
Color color1 = Color.LightBlue;
Color color2 = Color.DarkBlue;
using (Brush backbrush =
new LinearGradientBrush(e.ClipRectangle, color1, color2,
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(backbrush, e.ClipRectangle);
}
}
You can show the size gripper by setting the form's SizeGripStyle to Show:
SizeGripStyle = SizeGripStyle.Show;
Or just set it in the designer.
EDIT: Look at this page for creating a transparent textbox (if the textbox is transparent, the gradient form background will show through.)